Rails : Capybara : When Checkboxes and Radio buttons are not found

There may come situation when you try to check(tick) the checkboxes via RSpec. using codes like

find('#agree_legal_guardian').click
find('#agree_terms').click

 

Problem was:

We have hidden the original checkbox and the fancy checkbox was being shown. Since the item was hidden Capybara was not able to find the element.

Solution

Instead of searching for hidden item, I triggered the click event on the Label for that Checkbox

within('.term-condition') do
  find('[for=agree_legal_guardian]').click
  find('[for=agree_terms]').click
end

Useful links

http://www.rubydoc.info/gems/capybara/1.0.0/Capybara/Node/Finders#find-instance_method

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s