@Test public void shouldAllowOptionsToBeDeselectedByReturnedValue() { WebElement selectElement = driver.findElement(By.name("multi")); Select select = new Select(selectElement); select.deselectByValue("eggs"); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(1, returnedOptions.size()); }
public List<Integer> getAllSelectedIndices(Supplier<By> by) { Select select = new Select(findElement(by)); List<WebElement> options = select.getOptions(); return select .getAllSelectedOptions() .stream() .map(options::indexOf) .collect(Collectors.toList()); }
@Test public void shouldAllowUserToDeselectOptionsByVisibleText() { WebElement selectElement = driver.findElement(By.name("multi")); Select select = new Select(selectElement); select.deselectByVisibleText("Eggs"); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(1, returnedOptions.size()); }
@Test public void shouldAllowOptionsToBeSelectedFromTheSelectElementThatIsNarrowerThanOptions() { driver.get(pages.selectPage); WebElement selectElement = driver.findElement(By.id("narrow")); Select select = new Select(selectElement); select.selectByIndex(1); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(1, returnedOptions.size()); }
@Test @Ignore(MARIONETTE) public void shouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections() { WebElement selectElement = driver.findElement(By.name("multi")); Select select = new Select(selectElement); select.deselectAll(); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(0, returnedOptions.size()); }
@Override public String[] getSelectedLabels(String selectLocator) { WebElement selectLocatorWebElement = getWebElement(selectLocator); Select select = new Select(selectLocatorWebElement); List<WebElement> allSelectedOptionsWebElements = select.getAllSelectedOptions(); return StringUtil.split(ListUtil.toString(allSelectedOptionsWebElements, "text")); }
@Test public void shouldReturnOptionWhichIsSelected() { WebElement selectElement = driver.findElement(By.name("selectomatic")); Select select = new Select(selectElement); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(1, returnedOptions.size()); String one = returnedOptions.get(0).getText(); assertEquals("One", one); }
@Test public void shouldReturnOptionsWhichAreSelected() { WebElement selectElement = driver.findElement(By.name("multi")); Select select = new Select(selectElement); List<WebElement> returnedOptions = select.getAllSelectedOptions(); assertEquals(2, returnedOptions.size()); String one = returnedOptions.get(0).getText(); assertEquals("Eggs", one); String two = returnedOptions.get(1).getText(); assertEquals("Sausages", two); }
public static String[] getSelectedLabels(WebDriver webDriver, String selectLocator) { WebElement selectLocatorWebElement = getWebElement(webDriver, selectLocator); Select select = new Select(selectLocatorWebElement); List<WebElement> allSelectedOptionsWebElements = select.getAllSelectedOptions(); String[] selectedOptionsWebElements = new String[allSelectedOptionsWebElements.size()]; for (int i = 0; i < allSelectedOptionsWebElements.size(); i++) { WebElement webElement = allSelectedOptionsWebElements.get(i); if (webElement != null) { selectedOptionsWebElements[i] = webElement.getText(); } } return selectedOptionsWebElements; }