How to get number of sizes of check-boxes i have selected, using selenium webdriver java?



  • As there are five number of check boxes in a page, i have selected two check boxes. so i want to get the number of size as two check box selected. How to get the number of size as two in selenium web-driver?

    Note: List boxes = driver.findElements(By.name("vehicle")).click(); System.out.println(boxes.size() + "Number of check boxes present in the page");

    it gives me the entire number of check boxes, As the above scenario is not needed.



  • driver.findElements(By.name("vehicle").click();
    int i = 0;
    for (WebElement we:driver.findElements(By.name("vehicle")) {
        if (we.isSelected()) { i++; }
    }
    System.out.println(i
                + " Number of check boxes present in the page");
    

    That should give no issues. But you are looping through an entire list to always come to the same answer, 1.



Suggested Topics

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