Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How Can i get this Xpath

enter image description here

I got the id for capturing.

//button[contains(text(),'Delete')][1] 

//button[@id='deletebtn']

but its have 10 duplicate values.can’t identify unique thing for capture the element.Please Help me to resolve

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As you haven’t shared full HTML I am assuming you want use the first locator of 10 matches.

You can use

//(button[contains(text(),'Delete')])[1] 

instead of

//button[contains(text(),'Delete')][1] 

In case, suppose you want to use an another element then change the match number. Like below,

//(button[contains(text(),'Delete')])[3] 

or

//(button[contains(text(),'Delete')])[4] 

Note: Selenium by default picks the first element if there are more than one match.

Always check your xPath in chrome console to make sure it is unique.

  • Press F12 in Chrome.
  • Go to elements section
  • Search ( CTRL + F)
  • Place the xpath and see, if your desired element is getting highlighted with 1/1 matching node. This means, your xPath is unique.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading