How to click on the second link with the same text using Capybara in Rails 3?

Viewed 42558

In a view file I have:

= link_to 'View', post
= link_to 'View', comment

In a spec file (I'm using Capybara):

click_on 'View'

It clicks on the first link, but I want it to click on the second one. How can I do it?

7 Answers

You could try to find all entries and deal with an array:

page.all('a')[1].click

Would help to have a class or use within to scope your search ;)

Related