I'm currently creating test scenarios for the aviasales.com website and I am attempting to confirm the status of a checkbox.
Locating and clicking on the checkbox was simple using the following code:
WebElement checkboxValue = driver.findElement(By.xpath("//label[@class='mewtwo-show_hotels__label']"));
checkboxValue.click();
The issue arises when checking the state with
boolean bool = checkboxValue.isSelected();
, as it consistently returns false even after being selected.
After researching, I came across suggestions to use JavaScript. I first attempted this in the console before implementing it in Java, yet encountered the same problem - always returning false:
var field = document.getElementsByClassName("mewtwo-show_hotels__label");
if (field[0].checked == true) {alert("1")} else {alert("2")}
Regardless of whether the checkbox is checked or not, I only received an alert with 2.
If Chrome's locator identifies the checkbox as ::before in the source code, what other approaches could I explore?
https://i.sstatic.net/518cp.png
Thank you!