Reputation: 19525
I want to click on the second of the two following links:
<a href="photo/1">photo</a>
<a href="photo/2">photo</a>
As you can see, the URLs are actually different, but the link title, "photo", is the same in both. I am not using IDs on my links, and there is no nesting class context by which to distinguish the links.
Ideally, I would like to be able to click even a third, or nth
ambiguous link.
An example of a DSL for this purpose would be something like:
click_link photo.title, match: 2
Upvotes: 2
Views: 2166
Reputation: 46846
I find that using all
is easier to read than locating by xpath:
all('a', :text => 'photo')[1].click
However, it not as fast as using xpath.
Upvotes: 3
Reputation: 17647
You should be able to use xpath for this. Something like:
find(:xpath, '//a[text()='photo'][2]').click
Upvotes: 1