Capybara Ambiguity Resolution

neilmarion picture neilmarion · Oct 30, 2012 · Viewed 52.3k times · Source

How do I resolve ambiguity in Capybara? For some reason I need links with the same values in a page but I can't create a test since I get the error

Failure/Error: click_link("#tag1")
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching link "#tag1"

The reason why I can't avoid this is because of the design. I'm trying to recreate the twitter page with tweets/tags on the right and the tags on the left of the page. Therefore it will be inevitable that identical links page shows up on the same page.

Answer

e-zinc picture e-zinc · Nov 14, 2012

My solution is

first(:link, link).click

instead of

click_link(link)