Reputation: 1283
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
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