How can I select a particular node within the XPath node sets by index?

0 votes

I use the below XPath to locate all 'Modify' buttons inside my data table.

//img[@title='Modify']

But, if there are more than one element, then how will I select one of them? I've tried the below but neither work:

//img[@title='Modify'][i]

and

//img[@title='Modify' and position() = i]

I have also tried XPath checker which is firefox extension. There are totally 13 matches found, but I have no idea how to select one of them...

Apr 20, 2018 in Selenium by kappa3010
• 2,010 points
157 views

1 answer to this question.

0 votes

There is no concept of 'i' in XPath. But you can actually use a number to select a particular 'nth' 'Modify' element in your page. This is how its done:

//img[@title='Modify'][1]

or

//img[@title='Modify'][nth-no-of-element]
answered Apr 20, 2018 by king_kenny
• 3,590 points

Related Questions In Selenium

0 votes
1 answer

How can I access the parent of a node with XPath?

Hey Hemant, we can use the double ...READ MORE

answered Jun 23 in Selenium by Anvi
• 9,830 points
25 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
248 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
621 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
237 views
0 votes
1 answer

How to select an Object by its class in Selenium?

When it comes to Selenium, XPath will ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,590 points
30 views
0 votes
1 answer