DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

checkbox in Capybara

🔗 Parent Note

👍 Way1:

Capybara::Node::Actions#check is easy and similar way with Capybara::Node::Actions#fill_in for the textbox.

example.

# will check a descendant checkbox with a name, id, or label text matching 'German'
page.check('German')

# will check `el` if it's a checkbox element
el.check()

👍 Way2: Workaround

But, when somehow it doesn't work, try to find the pair label, and click it. It should be work because a checkbox is usually pair with label.

<input type="checkbox" value="1" name="workaround[item_id]" class="workaround" id="workaround_1">
find("label[for='workaround_1']").click

Top comments (0)