-1

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

  • Welcome to StackOverflow. While asking the question on this forum also mention what you have tried and paste you code. Go through the link on How to ask a good question and Help Center – Alok Aug 9 at 13:53
1

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();
  • Thank u so much – Purushothaman Aug 7 at 12:57
  • Most welcome. Could you mark the question as accepted? It really helps to keep contributors in the site. – João Farias Aug 7 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.