How to click a switch with capybara in ruby ​​on a rails app

I am trying to select a switch with capybara and it cannot find the switch. Here is my rspec test, view and error. Please note that I use factories for users, 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 %> 

The error I am getting is:

 Unable to find radio button "Development 1" 
+5
source share
1 answer

You use choose to check the radio buttons, but there is check_box_tag in your provided view code. Try either changing check_box_tag to radio_button_tag , or if you really want to check the box, use check instead of choose .

Note that you can also select a radio button or checkbox by searching for an identifier using find. This helps when capybara does not find it by tag name. Try:

 find(:css, "#skill_ids_[value='#{skill.id}']").set(true) 
+3
source

Source: https://habr.com/ru/post/1208838/


All Articles