Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select multiple alternate checkboxes in selenium webdriver

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(); } }checkboxHow to select multiple alternate checkboxes in selenium webdriver?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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(); 
    }
} 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading