public boolean isChecked(String locator) { WebElement checkBox = driver.findElement(loc.autoLocator(locator)); if (!checkBox.getAttribute("type").toLowerCase().equals("checkbox")) { throw new InvalidElementTypeException("This elementLocator is not a checkbox!"); } if (checkBox.getAttribute("checked").equals("checked")) { return true; } else { return false; } } }
/** * Return the raw code to search for a specific locator as a String. * * @param locator * @return */ public final String locatorAsString(String locator) { String[] locatorParts = autoLocator(locator).toString().split(":", 2); String locatorType = locatorParts[0].trim(); String locatorText = locatorParts[1].trim(); if (locatorType.equals("By.selector")) { locatorType = "By.cssSelector"; } return locatorType + "(\"" + locatorText + "\")"; }
public void uncheck(String locator) { WebElement checkBox = driver.findElement(loc.autoLocator(locator)); if (!checkBox.getAttribute("type").toLowerCase().equals("checkbox")) { throw new InvalidElementTypeException("This elementLocator is not a checkbox!"); } if (checkBox.isSelected()) { checkBox.click(); } }
public void check(String locator) { WebElement checkBox = driver.findElement(loc.autoLocator(locator)); if (!checkBox.getAttribute("type").toLowerCase().equals("checkbox")) { throw new InvalidElementTypeException("This elementLocator is not a checkbox!"); } if (!checkBox.isSelected()) { checkBox.click(); } }