Posted 5 months ago. Visible to the public.

Capybara 'fill_in': Ambiguous match for different input names

When you have two inputs, where one contains the name of the other (eg. Name and Name with special treatment), Capybara's fill_in method will fail with the following message:

Copy
Ambiguous match, found 2 elements matching visible field "Name" that is not disabled (Capybara::Ambiguous)

You can force Capybara to match exactly what you are typing (which makes your tests better anyways) with match: :prefer_exact:

Copy
name = 'Name' value = 'Bettertest Cucumberbatch' fill_in(field, with: value, match: :prefer_exact)

Furthermore, we recommend setting Capybara's matching strategy globally to :prefer_exact. This will positively affect all you steps (including those of gems like Spreewald) as it prevents the Capybara::Ambiguous error in the edge case when two fields are matching the given name, but one of the matches includes the name only as a substring,

Copy
Capybara.match = :prefer_exact

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Jakob Scholz
Last edit:
4 months ago
by Michael Leimstädtner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Jakob Scholz to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more