HillHacker HillHacker - 1 year ago 119
Java Question

How to check all check-boxes one by one in selenium web driver with the java?

I am using the below code , The test case is not failing but the code is not checking the check-boxes.

public void Test_CheckBox_Check()throws InterruptedException {

List<WebElement> els = driver.findElements(By.xpath("//md-checkbox[@aria-checked='false']"));
for ( WebElement el : els ) {



Test Case is not failing
Xptha and the elements

enter image description here

Answer Source

The locator you are using might be the causing the issue try with below:

//div[@class='ng-scope flex-20']//following::md-checkbox**[@role='checkbox']**

You may omit the part in asterisk if all the elements that are identified by md-checkbox are checkboxes.

Below code worked for me in another case:

List<WebElement> checkboxes = driver.findElements(By.xpath("//div[@class='control-group']//following::input[@type='checkbox']"));
        for(WebElement check:checkboxes){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download