How To handle Checkbox in Selenium using Java

          Handling Checkbox in Selenium 

In this tutorial we are going to learn how to automate the checkbox in selenium webdriver using java.
  • How to select Check box in Selenium Webdriver using java ?
Click() - By using the click method we select checkbox in selenium webdriver.

Selenium Code 
// how to select check box in selenium 
driver.findElement(By.xpath("//span[@class='rct-checkbox']")).click();
System.out.println("Checkbox Selected successfully ");

  • How to verify check box is selected in selenium webdriver ?
isSelected()- In selenium webdriver to check whether the checkbox is selected or not we use isSelected () method .

Selenium Code
//How verify check box is selected by default or not
WebElement Checkbox=driver.findElement(By.xpath("//span[@class='rct-checkbox']"));
boolean bl=Checkbox.isSelected();
System.out.println(bl);
if (bl==false) {
Checkbox.click();
System.out.println("Check box selected Successfully");
}
else {
System.out.println("checkbox is not selected by defalt ");
}

  • How to check that checkbox is enable or not in selenium ?
isEnable()- To verify a checkbox is in disable mode or enable mode we use a predefine method known as isEnable method
Selenium Code 

How to verify check box enabled or not 

WebElement Checkbox=driver.findElement(By.xpath("//span[@class='rct-checkbox']"));

boolean bl=Checkbox.isEnabled();

System.out.println(bl);

if (bl==true) {

Checkbox.click();

System.out.println("Check box selected Successfully");

}

else {

System.out.println("Check box is not enable ");

}

  • How to verify checkbox available or not on webpage using selenium 
isDisplayed ()- To verify that a Check box is displayed on webpage or not we use predefine method isDisplayed.

Selenium Code-
//How to check checkbox is present on webpage or not
WebElement Checkbox=driver.findElement(By.xpath("//span[@class='rct-checkbox']"));
boolean bl=Checkbox.isDisplayed();
System.out.println(bl);
if (bl==true) {
Checkbox.click();
System.out.println("Check box selected Successfully");
}
else {
System.out.println("checkbox is not present ");
}

Hope !!! Above tutorial of "how to handle checkbox in selenium " helpful for you ...
Team ,
QA acharya

Tags : Checkbox in selenium webdriver , handling checkbox in selenium using java , how to select Check box in selenium webdriver using java

How to handle checkbox in selenium

 

Post a Comment

0 Comments