The following is Slim.
.checkboxes__item
= f.check_box :insert_thumbnail, { checked: @article.new_record? || @article.insert_thumbnail, class: 'a-toggle-checkbox' }
= f.label :insert_thumbnail, 'insert thumbnail?'
HTML
<input name="article[insert_thumbnail]" type="hidden" value="0">
<input class="a-toggle-checkbox"
type="checkbox"
value="1"
checked="checked"
name="article[insert_thumbnail]"
id="article_insert_thumbnail">
<label for="article_insert_thumbnail">insert thumbnail?</label>
</div>
I would like to check this checkbox in the E2E test, but it does not work.
check 'insert thumbnail?', visible: false
Error:
ArticlesTest#test_uncheck_checkbox_whether_to_display_thumbnail_in_body:
Selenium::WebDriver::Error::ElementNotInteractableError: element not interactable
(Session info: headless chrome=117.0.5938.62)
test/system/articles_test.rb:292:in `block in <class:ArticlesTest>'
I understand this error to mean that the element exists but cannot be manipulated.
Is this due to CSS? Or should I just pass an option other than visible to the check method?
.a-toggle-checkbox
+size(0)
display: block
+position(fixed, left 0)
opacity: 0
overflow: hidden
visibility: hidden
- Set the visible option to true
uncheck 'insert thumbnail?', visible: true
Error:
ArticlesTest#test_uncheck_checkbox_whether_to_display_thumbnail_in_body:
Capybara::ElementNotFound: Unable to find visible checkbox "insert thumbnail?" that is not disabled
test/system/articles_test.rb:292:in `block in <class:ArticlesTest>'
- Scroll to
scroll_to 'insert thumbnail?'
uncheck 'insert thumbnail?', visible: false
- find + click
find('label[for=article_insert_thumbnail]').click
=> I can click.But I want to use check/uncheck method.
Due to the fact that your check boxes are not visible and you are are targeting the label element with your selector, I believe you just need to enable the
automatic_label_clickoption.Or pass that option explicitly to the
checkmethod e.g.Here is the actual method, which has a secondary attempt if this option is true, and the error is "catchable" which it is in your case (See below).
This will then look for the label and call click (which seems to work for you now)
For Reference the "Catchable Errors" (
catch_error?(e) #=> true) in this case would be: