How to i find the count of check boxes is selected?



  • In the UI there are 50 check boxes. If I selected 20 check boxes. How to I find count of 20 is selected?



  • Selenium provides the isSelected method, which returns whether a checkbox is selected. Then you can use it to filter in only the selected checkboxes.

    List<WebElement> checkboxes = driver.findElements(...)
    List<WebElement> selectedCheckboxes = checkboxes.stream()
                                         .filter(checkbox -> checkbox.isSelected()).collect(Collectors.toList())
    Integer numberOfSelectedCheckboxes = selectedCheckboxes.size();
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2