Italian Trulli

How To Handle Checkbox in Selenium Using Java

Test Tribe
.
               Handling Checkbox in Selenium WebDriver 
 

How To Select the Check Box in Selenium Webdriver Using Java?

Click()  
By using the click method we select or click 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 to Uncheck the Checkbox in Selenium web driver using Java?
Click()
Click Method is used to uncheck the check box is selenium webdriver.

Selenium Code
//How to 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==True) {
Checkbox.click();
System.out.println("Check box unceck Successfully");
}
else {
System.out.println("checkbox is not selected by defalt ");
}

How To Verify whether Check Box is Selected or not in the Selenium Web Driver?

isSelected()
In selenium webdriver to check whether the checkbox is selected or not we use the isSelected () method.

Selenium Code
//How to 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 whether the Checkbox is Enabled or not in Selenium Webdriver Using Java?

isEnable()
To verify whether a checkbox is in disable mode or enable mode we use a predefined method known as the isEnable method

Selenium Code 
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 Whether Checkbox is Available or Not on Webpage Using Selenium Webdriver Java?
 
isDisplayed () 
To verify whether a Check box is displayed on the webpage or not we use the predefined method is displayed.

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 ");
}


Hope !!! The above tutorial on "how to handle checkbox in selenium "is helpful for you ...

Team,
QA acharya

How to select Checkbox in Selenium

 

Post a Comment

0 Comments