Saturday, March 28, 2015

How to Select the check boxes one by one 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 CheckBoxes {

   
    public static void main(String[] args){
       
       
         WebDriver dr = new FirefoxDriver();
         dr.get("http://www.ironspider.ca/forms/checkradio.htm");
          dr.manage().window().maximize();
         List<WebElement> CheckBoxList = dr.findElements(By.name("color"));
         
         for(int i =0; i < CheckBoxList.size();i++) {
         
             CheckBoxList.get(i).click();
         System.out.println(CheckBoxList.get(i).getAttribute("Value"));
         
         }
    }
}

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...