There is an open feature request, Capybara Github Issue 1256, to have have_selector
(and others) support exact text matching.
However, for now (in Capybara 2.x), the :exact
option does not apply to the :text
option. If I recall correctly, it is the following piece of code (from query.rb) that does the text option filtering. As you can see, there is no logic or consideration of the :exact
option.
def matches_filters?(node)
if options[:text]
regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
return false if not node.text(visible).match(regexp)
end
As per the Capybara docs, the :exact
option is actually to:
Control whether
is
expressions in the given XPath match exactly or partially
This is basically only used in the Capybara::Node::Actions, where the text (or id, name, etc.) is not specified as an option - ex:
# Will match links that exactly match 'Password'
click_link('Password', :exact => true)
# Will match links that contain the word 'Password' - ex 'Password Confirmation'
click_link('Password', :exact => false)