I'm trying to select a radio button with capybara and it can't find the radio button. Here is my rspec test, view and error. Please note that I am using factories for user, skills, etc.
Rspec test
scenario "user chooses a couple skills and moves on to bio" do
user = create(:user)
skill = create(:skill)
skill_two = create(:skill)
skill_three = create(:skill)
sign_in(user)
visit onboard_skills_path
choose(skill.name)
end
View
<%= form_for(:onboard_skill, url: onboard_skills_path) do |f| %>
<ul>
<% @skills.each do |skill| %>
<li>
<%= check_box_tag("skill_ids[]", skill.id, current_user.onboard_skill_ids.include?(skill.id)) %>
<%= f.label(skill.name) %>
</li>
<% end %>
</ul>
<%= f.submit "Next >", class: "submit_skills" %>
<% end %>
Error I am getting is:
Unable to find radio button "Development 1"
You are using choose
to test for a radio button but in your provided view code you have a check_box_tag
. Try either changing check_box_tag
to radio_button_tag
or if you really want a check box, use check
instead of choose
.
Note that you can also select a radio button or check box by searching for the id using find. This helps when capybara does not find it by the label name. Try:
find(:css, "#skill_ids_[value='#{skill.id}']").set(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With