mardi 16 janvier 2018

How to locate state of a checkbox element with java+selenium which could not be recognized as a checkbox even with javascript

I'm implementing test cases for aviasales.com web sites and I'm trying to validate state of the checkbox.

I could easily find the checkbox and even click on it via:

WebElement checkboxValue = driver.findElement(
      By.xpath("//label[@class='mewtwo-show_hotels__label']"));
            checkboxValue.click();

The problem is that boolean bool = checkboxValue.isSelected(); returns only false even it was selected.

I googled a lot and found an advice to use JavaScript for that, so I tried from the console before Java implementation but same thing happens - always false:

var field = document.getElementsByClassName("mewtwo-show_hotels__label");
if (field[0].checked == true) {alert("1")} else {alert("2")}

and I got only alert with 2 no matter what is a checkbox condition (selected or not)

What else can I try here if chrome locator identifies checkbox as ::before in source code?

enter image description here

Thank you!




Aucun commentaire:

Enregistrer un commentaire