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()


Enter fullscreen mode Exit fullscreen mode

πŸ‘ 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">


Enter fullscreen mode Exit fullscreen mode


find("label[for='workaround_1']").click


Enter fullscreen mode Exit fullscreen mode

Top comments (0)