== Matchers ==

Capybara finds an element either using Domain-specific language or XPath/CSS Selectors. Partial matches can lead to unexpected results. Two or more matches can even result in a failure with an Ambiguous match error. The following are the matching strategies supported by Capybara: <ref>https://github.com/jnicklas/capybara#matching</ref>

  • :one – raises an error when more than one match found
  • :first – simply picks the first match – Don’t use this!
  • :prefer_exact – finds all matching elements, but will return only an exact match discarding other matches
  • :smart – depends on the value for Capybara.exact. If set to true, it will behave like :one. Otherwise, it will first search for exact matches. If multiple matches are found, an ambiguous exception is raised. If none are found, it will search for inexact matches and again raise an ambiguous exception when multiple inexact matches are found.