user3814030
user3814030

Reputation: 1283

Capybara have_selector is not working on checkbox

On my view I have a checkbox

<input type="checkbox" id="modal-checkbox" class="painter-modal-checkbox" data-reactid=".1.1:1.0.0">

On my capybara code, I am trying to use the have_selector method

expect(page).to have_selector("#modal-checkbox")

This fails, when I am tracing the page with

print page.html

I can confirm that my html code is there, why does this test fails.

Upvotes: 3

Views: 1024

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

This is usually because the field isn't actually visible because it's hidden via CSS. With checkboxes this is often because the design calls for the label to be used to show the selected state of the checkbox while the actual checkbox is hidden. To check if visibility is the issue you can pass visible: false to have_selector, however 99% of the time you shouldn't be checking for invisible items since a user wouldn't be able to see them or interact with them

Upvotes: 2

Related Questions