Home > Blockchain >  How Can i get this Xpath
How Can i get this Xpath

Time:11-30

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

CodePudding user response:

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.
  • Related