tags:

views:

458

answers:

1

When there is more than a single element with the same locator in a page, how should the next elements be referenced?

Using Xpath locators it's possible to add array notation, e.g. xpath=(//span/div)[1] But with simple locators?

For example, if there are 3 links identified by "link=Click Here", simply appending [3] won't get the 3rd element.

And where is the authoritative reference for addressing array of elements? I couldn't find any.

+1  A: 

Selenium doesn't handle arrays of locators by itself. It just returns the first element that meets your query, so if you want to do that, you have to use xpath, dom or even better, css.

So for the link example you should use:

selenium.click("css=a:contains('Click Here'):nth-child(3)")
Santi
thanks! i had no idea it's possible (and is much more readable than xpath)
Berry Tsakala