/** * Select all options that display text matching the argument. That is, when given "Bar" this * would select an option like: * * <option value="foo">Bar</option> * * @param text The visible text to match against */ public void selectByVisibleText(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) { option.setSelected(); if (isMultiple()) { return; } } }
/** * Select all options that have a value matching the argument. That is, when given "foo" this * would select an option like: * * <option value="foo">Bar</option> * * @param value The value to match against */ public void selectByValue(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) { option.setSelected(); if (isMultiple()) { return; } } }
/** * 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(); } } }
/** * Select all options that have a value matching the argument. That is, when given "foo" this * would select an option like: * * <option value="foo">Bar</option> * * @param value The value to match against */ public void selectByValue(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) { option.setSelected(); if (isMultiple()) { return; } } }
/** * 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(); } } }
List<WebElement> options = element.findElements(By.xpath(".//option[. = " + escapeQuotes(text) + "]")); for (WebElement option : options) { option.setSelected(); } else { candidates = element.findElements(By.xpath(".//option[contains(., " + escapeQuotes(subStringWithoutSpace) + ")]"));