3
votes

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

2
It would help if you show the html of the element that you are trying to get.Justin Ko

2 Answers

1
votes

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'
0
votes

You mixed up single and double quotes.

#       ⇓         ⇓
fill_in 'firstName"