0

does maybe someone know how to handle or read out the status (true/false) of a checkbox with selenium, when there isn't any variable which toggles on the html page. I already tried the common functions .isSelected() and .isEnabled(), but these read out just the value which isn't available.

Do anyone know if there is a way to get this status ? In Addition a screenshot of the xml and which element it is.

Would be great if someone has an idea. I'm programming in Java.

Code in addition

5
  • Show your complete code-line for the same Commented Oct 12, 2021 at 10:06
  • if(Value <= 1 && (driver.findElement(chooseLeistung("0-1kW")).isEnabled()) == false) driver.findElement(chooseLeistung("0-1kW")).click(); maybe it seems to be confusing. it means that it should toggle the checkbox if it is false (toggled off). the element is figured out right with the xpath, because the click is working. Commented Oct 12, 2021 at 10:09
  • @Andreas what is chooseLeistung("0-1kW")? Are you handling input type='checkbox' node? Commented Oct 12, 2021 at 10:11
  • private static By chooseLeistung(String Leistung){ switch(Leistung){ case "0-1kW": return By.xpath("//*[@id=\"filter_details_container_3\"]/div[1]/label"); case "1-2,2kW": return By.xpath("//*[@id=\"filter_details_container_3\"]/div[2]/label"); ... } } just a method to return the by Commented Oct 12, 2021 at 10:12
  • the xpath in my picture is different, but all these checkboxes are the same style. just need an idea how to handle this Commented Oct 12, 2021 at 10:15

1 Answer 1

0

You're trying to get "selected" state from label while isSelected method should only be applied to input of type "checkbox" element. So make sure to select correct element:

driver.findElement(By.id("checkbox_filter_details_text_1_1")).isSelected();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.