Saturday, March 28, 2015

How to select a specific check box using selenium?

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 SelectSpecificCheckBox {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         WebDriver dr = new FirefoxDriver();
         dr.get("http://www.ironspider.ca/forms/checkradio.htm");
         
         List<WebElement> CheckBoxList = dr.findElements(By.name("color"));
         
         // Click on the first check box
         CheckBoxList.get(0).click();   
         
         // Click on the second check box
         CheckBoxList.get(1).click();   
         
         // Click on the third check box
         CheckBoxList.get(2).click();

    }

}

No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...