Posted 13 days 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)

Using Spreewald

When using our Spreewald gem, you might want to override the fill-in-step as soon as you encounter the ambiguous matching problem.

Copy
# step_definitions/spreewald_overrides.rb # Override to force exact matching for input names When /^(?:|I )fill in "([^"]*)" (?:with|for) "([^"]*)"$/ do |field, value| patiently do fill_in(field, with: value, match: :prefer_exact) end end
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Jakob Scholz
Last edit:
13 days ago
by Jakob Scholz
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