You are on page 1of 2

PRACTICAL NO 09

Aim: Write and test a program to count the number of check boxes on the page checked and
unchecked count.
Requirement: eclipse , Registration Page.
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.List;

public class check {

public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.29.1-win64\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("file:///D:/java%20or%20what/Regis.html");
int chk=0,unchk=0,rchk=0,unrchk=0;
List<WebElement>
c1st=driver.findElements(By.xpath("//input[@type='checkbox']"));
for (WebElement wb:c1st)
{
if (wb.isSelected())
{
chk+=1;
}
else
{
unchk+=1;
}
}
System.out.println("Checkbox="+chk);
System.out.println("UnCheckedbox="+unchk);

List<WebElement>
r1st=driver.findElements(By.xpath("//input[@type='radio']"));
for (WebElement wb:r1st)
{
if (wb.isSelected())
{
rchk+=1;
}
else
{
unrchk+=1;
}
}
System.out.println("Checked Radio="+chk);
System.out.println("UnChecked Radio="+unchk);

Output:

You might also like