private void removeAllSelections(List<WebElement> options) { for (WebElement option : options) { if (option.isSelected()) option.toggle(); } }
/** * Deselect the option at the given index. This is done by examing the "index" attribute of an * element, and not merely by counting. * * @param index The option at this index will be deselected */ public void deselectByIndex(int index) { String match = String.valueOf(index); for (WebElement option : getOptions()) { if (match.equals(option.getAttribute("index")) && option.isSelected()) { option.toggle(); } } }
/** * Deselect the option at the given index. This is done by examing the "index" attribute of an * element, and not merely by counting. * * @param index The option at this index will be deselected */ public void deselectByIndex(int index) { String match = String.valueOf(index); for (WebElement option : getOptions()) { if (match.equals(option.getAttribute("index")) && option.isSelected()) { option.toggle(); } } }
public boolean select(List<WebElement> fromOptions, String selectThis, boolean setSelected, boolean allowMultipleSelect) { try { int index = Integer.parseInt(selectThis); WebElement option = (WebElement) fromOptions.get(index); if (setSelected) option.setSelected(); else if (option.isSelected()) { option.toggle(); } return true; } catch (Exception e) { // Do nothing. Handled below } return false; } }
public boolean toggle() { dispatcher.beforeChangeValueOf(element, driver); boolean result = element.toggle(); dispatcher.afterChangeValueOf(element, driver); return result; }
/** * Uncheck a toggle-button (checkbox/radio) * * @param locator an <a href="#locators">element locator</a> */ public void uncheck(String locator) { WebElement element = findElement(locator); if (element.isSelected()) element.toggle(); }
public boolean toggle() { dispatcher.beforeChangeValueOf(element, driver); boolean result = element.toggle(); dispatcher.afterChangeValueOf(element, driver); return result; }
public boolean select(List<WebElement> fromOptions, String selectThis, boolean setSelected, boolean allowMultipleSelect) { boolean matchMade = false; Iterator<WebElement> allOptions = fromOptions.iterator(); while (allOptions.hasNext()) { WebElement option = allOptions.next(); boolean matchThisTime = selectOption(option, selectThis); if (matchThisTime) { if (setSelected) option.setSelected(); else if (option.isSelected()) { option.toggle(); } } matchMade |= matchThisTime; if (matchMade && !allowMultipleSelect) return true; } return matchMade; }
/** * Deselect all options that display text matching the argument. That is, when given "Bar" this * would deselect an option like: * * <option value="foo">Bar</option> * * @param text The visible text to match against */ public void deselectByVisibleText(String text) { StringBuilder builder = new StringBuilder(".//option[. = "); builder.append(escapeQuotes(text)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder.toString())); for (WebElement option : options) { if (option.isSelected()) { option.toggle(); } } }
/** * Deselect all options that have a value matching the argument. That is, when given "foo" this * would deselect an option like: * * <option value="foo">Bar</option> * * @param value The value to match against */ public void deselectByValue(String value) { StringBuilder builder = new StringBuilder(".//option[@value = "); builder.append(escapeQuotes(value)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder.toString())); for (WebElement option : options) { if (option.isSelected()) { option.toggle(); } } }
/** * Deselect all options that have a value matching the argument. That is, when given "foo" this * would deselect an option like: * * <option value="foo">Bar</option> * * @param value The value to match against */ public void deselectByValue(String value) { StringBuilder builder = new StringBuilder(".//option[@value = "); builder.append(escapeQuotes(value)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder.toString())); for (WebElement option : options) { if (option.isSelected()) { option.toggle(); } } }
/** * Deselect all options that display text matching the argument. That is, when given "Bar" this * would deselect an option like: * * <option value="foo">Bar</option> * * @param text The visible text to match against */ public void deselectByVisibleText(String text) { StringBuilder builder = new StringBuilder(".//option[. = "); builder.append(escapeQuotes(text)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder.toString())); for (WebElement option : options) { if (option.isSelected()) { option.toggle(); } } }
/** * Clear all selected entries. This is only valid when the SELECT supports multiple selections. * * @throws UnsupportedOperationException If the SELECT does not support multiple selections */ public void deselectAll() { if (!isMultiple()) { throw new UnsupportedOperationException( "You may only deselect all options of a multi-select"); } for (WebElement option : getOptions()) { if (option.isSelected()) { option.toggle(); } } }
/** * Clear all selected entries. This is only valid when the SELECT supports multiple selections. * * @throws UnsupportedOperationException If the SELECT does not support multiple selections */ public void deselectAll() { if (!isMultiple()) { throw new UnsupportedOperationException( "You may only deselect all options of a multi-select"); } for (WebElement option : getOptions()) { if (option.isSelected()) { option.toggle(); } } }
public ResultType call() throws Exception { response = newResponse(); response.setValue(getElement().toggle()); return ResultType.SUCCESS; }
public ResultType call() throws Exception { response = newResponse(); response.setValue(getElement().toggle()); return ResultType.SUCCESS; }