0

The scenario is:

  1. Try to add experience in linkedin.
  2. Then click on save button to save the added experience.

The below is html code for this button:

<button class="pe-form-footer__action--submit form-submit-action Sans-15px-white-100%" type="submit">
  Save
</button>

I am trying to find it by xpath using:

@FindBy (xpath = "//*[contains(text(), 'Save')]")
WebElement saveExperienceButton;

Following screenshot may help:

enter image description here

I will appreciate your help.

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131

3 Answers3

1

if you do not mind css/xpath selectors that do not look very elegant, you can always open up Chrome developer tools on the website you wanna test with Selenium, mark the DOM elements you wanna access and in the context menu choose 'Copy xpath' or 'copy selector':

Chrome devtools, copy xpath or css selector

  • Thanks for your reply, but it will not working because the xpath will be generated with the div id which it is auto generated and has been changed if you refresh the page – AlaaEldein Ali Sep 24 '18 at 08:01
0

Try this xpath:

(//*[text()='Save'])[2]

On my profile there are 2 Save buttons - the second one is the skill save. Also, you might want to check this question for the contains syntax.

skandigraun
  • 741
  • 8
  • 21
0

Creating an XPath using text is a less preferable way. instead of that use other attribute value which is unique. for ex: in your case

//footer//*[contains(@class, 'form-submit')] 
cruisepandey
  • 28,520
  • 6
  • 20
  • 38