Thursday, 19 November 2015

write code to select all the checkboxes

package interview;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Writecodetoselectallthecheckboxes {
public static WebDriver d;
@Test
public static void checkallCheckBoxex()
{
    d=new FirefoxDriver();
    d.get("http://www.ironspider.ca/forms/checkradio.htm");
    d.manage().window().maximize();
    d.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
   
    //Logic to print all checkboxes name and select all check boxes
    List<WebElement> checkBoxList =d.findElements(By.xpath("//*[@id='Content']/div[1]/blockquote[1]/form/input"));
    for(int i=0;i<checkBoxList.size();i++)
    {
        System.out.println(checkBoxList.get(i).getAttribute("value"));
        checkBoxList.get(i).click();
    }
   
   
}
}

No comments:

Post a Comment