How To Handle Checkbox in Selenium Using Java

.
           Handling Checkbox in Selenium
 
  • How to select Check box in Selenium Webdriver using java ?
Click() - By using the click method we select the 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 do verify check box is selected in the selenium webdriver ?
isSelected()- In selenium webdriver to check whether the checkbox is selected or not we use the 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 do check that checkbox is enabled or not in selenium?
isEnable()- To verify a checkbox is in disable mode or enable mode we use a predefined method known as the isEnable method
Selenium Code 

How to verify check box is 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 a webpage using selenium 
isDisplayed ()- To verify that a Check box is displayed on webpage or not we use the predefine method isDisplayed.

Selenium Code-
//How to check checkbox is present on the 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 ");
}

What is a CheckBox?
A checkbox is a GUI widget that allows the user to make a Binary choice ie. Users may get more than 2 options.
In this tutorial, we are going to learn how to automate the checkbox in selenium webdriver using java.


Hope !!! Above tutorial on "how to handle checkbox in selenium "is 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