Read more

Capybara 'fill_in': Ambiguous match for different input names

Jakob Scholz
February 05, 2020Software engineer at makandra GmbH

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:

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

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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

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

Furthermore, we recommend setting Capybara's matching strategy Show archive.org snapshot globally to :prefer_exact. This will positively affect all you steps (including those of gems like Spreewald Show archive.org snapshot ) 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,

Capybara.match = :prefer_exact
Posted by Jakob Scholz to makandra dev (2020-02-05 16:40)