Home > Net >  How to select multiple alternate checkboxes in selenium webdriver
How to select multiple alternate checkboxes in selenium webdriver

Time:09-30

driver.get("183.82.103.245/nareshit/login.php"); 
driver.findElement(By.name("txtUserName")).sendKeys("nareshit"); 
driver.findElement(By.name("txtPassword")).sendKeys("nareshit");
driver.findElement(By.name("Submit")).click();
Thread.sleep(3000);
driver.switchTo().frame("rightMenu");
List<WebElement> AllCheckboxes = driver.findElements(By.xpath("//input[@type='checkbox']"));;
int size = AllCheckboxes.size();
System.out.println(size);
for(int i=0;i<size;i  ) {
    (AllCheckboxes).get(i).click(); 
}
Thread.sleep(5000); driver.close(); 
} }

checkbox

How to select multiple alternate checkboxes in selenium webdriver?

I have written code for selecting multiple checkboxes at a time. I wanted to try for clicking on multiple alternate checkboxes.

CodePudding user response:

There are many ways you can achieve that - clicking alternate checkboxes, just add a simple logic:

int counter = 1;
for(int i=0;i<size;i  ) { 
    counter  ;
    if ((counter % 2) == 0) {
        (AllCheckboxes).get(i).click(); 
    }
} 
  • Related