Checkbox are an often used element in the web application, But how do you work with them in selenium web driver or automation testing.
I am doing an automation testing of one application and I am facing one scenario to verify Check-box are checked or not using automation code
Solution :
There are two ways to approach this first one check if an element has a checked attribute or not, Checked attribute you can check in fire-bug for particular checkbox(a.k.a. performing an attribute lookup), another one by asking an element has been selected or not, you can check selected or isselected using webdriver inbuilt method
Below is CSS code to verify checked and unchecked attribute:
unchecked
checked
I am doing an automation testing of one application and I am facing one scenario to verify Check-box are checked or not using automation code
Solution :
There are two ways to approach this first one check if an element has a checked attribute or not, Checked attribute you can check in fire-bug for particular checkbox(a.k.a. performing an attribute lookup), another one by asking an element has been selected or not, you can check selected or isselected using webdriver inbuilt method
Below is CSS code to verify checked and unchecked attribute:
unchecked
checked
Java Code :
public void VerifyChkbox(WebElement chkbox){
boolean checkstatus;
checkstatus=chkbox.isSelected();
if (checkstatus==true){
System.out.println("Checkbox is already checked");
}
else
{
chkbx1.click();
System.out.println("Checked the checkbox");
}
}
Same code is applicable for unchecked