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 21, 2018 in Selenium by kappa3010
• 2,090 points
4,340 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 21, 2018 by king_kenny
• 3,710 points

Related Questions In Selenium

–1 vote
1 answer

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

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

answered Jun 24, 2019 in Selenium by Anvi
• 14,150 points
12,927 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

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,500 points
12,711 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
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,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 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 14, 2018 in Selenium by king_kenny
• 3,710 points
760 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP