Reputation: 483
I was trying Capybara for the first time and having trouble with it finding my form. I'm using Rspec, Capybara, Rails 3.2.8, and Twitter Bootstrap.
In my test, I had:
before do
choose "Residential"
choose "Storage"
fill_in "Customer Location", with: 30082
fill_in "datepicker", with: 2012-12-02
fill_in "Email", with: "[email protected]"
fill_in "Phone", with: "555-555-5555"
end
And was getting the error:
Failure/Error: choose "Residential"
Capybara::ElementNotFound:
cannot choose field, no radio button with id, name, or label 'Residential' found
In my form, I had (excerpt):
<%= quote.radio_button :customer_type, "Residential"%>
<%= quote.label "Residential", class:"radio inline" %>
When I fired up the server, I could see the form and Firebug showed that I had a label named "Residential" associated with the form element.
After searching for the problem and finding this post: Capybara not finding form elements (among others), I couldn't figure out why it wasn't working.
Upvotes: 1
Views: 1622
Reputation: 483
I ultimately went back to Capybara's Rubydocs ( http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions ) and found the section on the "Choose" method.
I didn't dive deep into the documentation, but I saw that it was looking for a "locator" in the :radio_button and so tried associating one directly.
I thus changed my form to (notice I added "id" to the form element):
<%= quote.radio_button :customer_type, "Residential", id:"Residential"%>
<%= quote.label "Residential", class:"radio inline" %>
and that portion of the test passed! I repeated with each of my form elements and everything performed as expected.
Hope this is useful to someone else.
Upvotes: 1