I'm having problems with Selenium not being able to verify that a visible an interactable checkbox element is indeed displayed. The problem is only with the checkbox; other elements on the page are verified fine.
The markup (snipped):
<div>
<input type="checkbox" id="innskuttegenkapital">
<div class="hb-label" data-e2e-selector="innskuttegenkapitalhb-checkbox-label">
<label for="innskuttegenkapital" id="innskuttegenkapital-label">Innskutt egenkapital</label>
</div>
</div>
</div>
I'm using PageFactory to create the web elements, and assertThat to verify visible or not:
Java code from the Page Object:
@FindBy(css = "[data-e2e-selector=innskuttegenkapitalhb-checkbox-label]")
WebElement innskuttegenkapitallabel;
@FindBy(css = "#innskuttegenkapital")
WebElement innskuttegenkapitalcheckbox;
Java code from the test step:
assertThat(page.innskuttegenkapitallabel.isDisplayed()).isTrue();
assertThat(page.innskuttegenkapitalcheckbox.isDisplayed()).isTrue();
The first assert (for the element with the data-e2e-selector) asserts true. But the second (for the element with the ID - the checkbox next to the label) asserts false.
I know the problem is with my code, because the checkbox is indeed visible and manually checkable when stopping the test.
Ideas? Please advice if I need to post more details or better desciption.