Automation Using Selenium Webdriver
Showing posts with label How to Check All the Checkboxes Present in a Page Using Selenium. Show all posts
Showing posts with label How to Check All the Checkboxes Present in a Page Using Selenium. Show all posts

Friday 25 November 2016

How to Check All the Checkboxes Present in a Page Using Selenium

This post tells you how to check all the checkboxes present in the page.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;


public class testng_3 {
@Test
public void checkbox() throws Exception
{
FirefoxDriver fd= new FirefoxDriver();
fd.manage().window().maximize();
fd.get(“http://www.flipkart.com/laptops/lenovo~brand/pr?sid=6bo,b5g&otracker=hp_nmenu_sub_electronics_0_Lenovo”);
Thread.sleep(10000);
List checkBoxes = fd.findElements(By.xpath(“//input[@type=’Checkbox’]”));
System.out.println(checkBoxes.size());
for(int i=0; i<checkBoxes.size(); i++){
System.out.println(checkBoxes.get(i).getText());
checkBoxes.get(i).click();
}
fd.close();
}
}