Alex
Alex

Reputation: 295

Regex for Capybara

Can I use RegEx with Capybara?

I am trying to do somth like

fill_in \firstName" type="text" name="(\w+)" value=""\, :with => 'sdsdsd' Capybara answers

Сapybara::ElementNotFound: Unable to find field \firstName\" type=\"text\" name=\"(\w+)\" value=\"\"\

Wrong syntax?

Thanks in advance

Upvotes: 3

Views: 883

Answers (2)

bjelli
bjelli

Reputation: 10070

You do not begin and end a regexp with backslashes \likeso\, you normally need slashes /likeso/. There is also the %r syntax that allows for different delimitors, see http://www.ruby-doc.org/core-2.0/Regexp.html

But all this does not apply in this case, because:

You cannot use a regexp as the first argument of fill_in, only a String. See the documentation at http://www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Actions:fill_in

You can use either the id, name or the label-text to locate the input field, so just using "firstName" should work for you:

 fill_in 'firstName', :with => 'sdsdsd'

Upvotes: 1

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

You mixed up single and double quotes.

#       ⇓         ⇓
fill_in 'firstName" 

Upvotes: 0

Related Questions