Issue
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();
} }
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.
Solution
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();
}
}
Answered By - AbiSaran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.