0 votes
1 view
in DevOps and Agile by (30k points)

I'm writing a Selenium test case. And here's the XPath expression I use to match all 'Modify' buttons within a data table.

//img[@title='Modify']

My question is, how can I visit the matched node sets by index? I've tried with

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

and

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

But neither works... I also tried with the XPath checker(One firefox extension). There's a total of 13 matches found, then I have totally no idea how am I gonna select one of them.. Or does XPath support specified a selection of nodes which are not under the same parent node?

1 Answer

0 votes
by (51.2k points)

To select a specified node within the XPath node use this 

//someName[3]

This line means all someName elements in the document those are the third someName child of their parent.

There may be a chance of having many elements

If you need exactly third someName element use this

  (//someName)[3]

Let me explain [] has more priority than //  and one more thing put all expressions of this type //someName in brackets when you need to specify a node of your selected node-list.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing certification!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...