How to obtain the value of a checkbox in capybara?

Dev S picture Dev S · Mar 5, 2012 · Viewed 15k times · Source

I want to check if a checkbox is checked using cucumber and capybara. I have checked the checkbox in my previous step and want to verify it by obtaining the value of the checkbox.

Answer

Jon M picture Jon M · Mar 6, 2012

Use the checked? method

e.g.:

my_box = find('#some_checkbox')
my_box.should be_checked  # Before Rspec 2.11

# OR using new syntax
expect(my_box).to be_checked  # Rspec 2.11