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
75 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
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,030 points
72 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
444 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
55 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
22 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.