I'm trying to write an xpath expression for a Selenium test. I'm a little confused as to how (if at all) I can pick a specific element of a return set. I have a basic xPath expression to select all the div
elements with a certain CSS class
//div[@class='step-title']
When I used a Firefox xpath extension, this expression returns 7 results
What I want to do is select the first (or second, third, etc) element of this result set. However, my instincts for path syntax fail me, because the following
//div[@class='step-title'][2]
Returns all 7 matches again.
I've tried several variations, all with the same result.
The reason I want to select a specific element is to test a feature that re-orders something on a page — i.e. "Does the first div contain the text "Checkout Method". If selecting a specific element is impossible, alternate suggestions on how to write a selenium test to accomplish my end goal would be appreciated.