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/
You can ensure that you find the first one using match:
find('.selector', match: :first).click
But importantly, you probably do not want to do this, as it will lead to brittle tests that are ignoring the duplicate-output code smell, which in turn leads to false positives that keep working when they should have failed, because you removed one matching element but the test happily found the other one.
The better bet is to use within:
within('#sidebar') do
find('.selector).click
end
This ensures that you're finding the element you expect to find, while still leveraging the auto-wait and auto-retry capabilities of Capybara (which you lose if you use find('.selector').click), and it makes it much clearer what the intent is.