Created
July 4, 2018 10:51
-
-
Save burythehammer/04c99a4b4b77a9af5ea2938c11b51dd5 to your computer and use it in GitHub Desktop.
Selecting a checkbox in selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final WebDriver driver; | |
protected void setCheckbox(By locator, boolean desiredState) { | |
WebElement element = driver.findElement(locator); | |
boolean selected = element.isSelected(); | |
if (checkboxNeedsToBeClicked(selected, desiredState)) { | |
element.click(); | |
} | |
} | |
private boolean checkboxNeedsToBeClicked(boolean selected, boolean desiredState) { | |
return !(selected == desiredState); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment