Select Multiple Checkboxes using Selenium Webdriver 3.8














package mypack;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Checkbox {

 public static void main(String[] args) {
  // TODO Auto-generated method stub


  String exepath = "C:\\Users\\Amit\\Downloads\\geckodriver-v0.19.1-win64//geckodriver.exe";
  System.setProperty("webdriver.gecko.driver", exepath);
  
  WebDriver driver = new FirefoxDriver();
  
  driver.get("http://www.seleniumeasy.com/test/basic-checkbox-demo.html");
  
  List<WebElement> els = driver.findElements(By.xpath("//input[@type='checkbox']"));
  
  for (WebElement el: els){
   
   if(!el.isSelected()){
    el.click();
   }
  } 
 }

}



0 comments:

Post a Comment