How to find an element by matching exact text of the element in Capybara

Use a regexp instead of a string for the value of the :text key:

find("a", :text => /\ABerlin\z/)

Check out the ‘Options Hash’ section of the Method: Capybara::Node::Finders#all documentation.

PS: text matches are case sensitive. Your example code actually raises an error:

find("a", :text => "berlin")
# => Capybara::ElementNotFound:
#    Unable to find css "a" with text "berlin"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)