checkbox selenium code example
Example 1: checkbox and radio button in selenium
- I locate it as just another web element AND CLICK.
- I would verify if checkbox is selected or not by
- .isSelected() method will return true if checkbox is selected.
- .isSelected() method will return false if checkbox is NOT selected.
syntax: checkbox.click();
syntax: checkbox.isSelected(); --> will return boolean: true/false
Example 2: checkbox selenium
- We locate, and we click on them.
isSelected() isSelected()--> true, else --> false
This method checks if the checkbox/radiobutton is selected or not selected.
isEnabled() isEnabled -> true, else --> false
This method checks if the checkbox/radiobutton is enabled to be clicked.
isDispalyed() isDispalyed()-> true, else --> false
verify the presence of a web element within the web page.
syntax: driver.findElement(LOCATOR).isSelected();
syntax: driver.findElement(LOCATOR).isEnabled();
StaleElementReferenceException:
A stale element reference exception is thrown in one of two cases
1- The element has been deleted entirely.
2- The element is no longer attached to the DOM.
WebElement checkbox = driver.findElement(LOCATOR);
checkbox.click; driver.navigate().refresh();
checkbox = driver.findElement(LOCATOR);
checkbox.click(); <--stale element reference exception will be thrown