Example usage for org.openqa.selenium WebElement findElements

List of usage examples for org.openqa.selenium WebElement findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current context using the given mechanism.

Usage

From source file:com.vaadin.framework8.samples.SpringCrudIT.java

License:Apache License

@Test
public void createContact() {
    doLogin();/*ww w .  ja v  a2 s.  c om*/

    List<WebElement> primaries = findElements(By.className("primary"));
    List<WebElement> newProduct = primaries.stream()
            .filter(element -> element.getText().endsWith("New product")).collect(Collectors.toList());

    Assert.assertEquals(1, newProduct.size());

    newProduct.get(0).click();

    WebElement form = findElement(By.className("product-form"));

    List<WebElement> fields = form.findElements(By.className("v-textfield"));

    WebElement productName = fields.get(0);
    productName.clear();
    productName.sendKeys("New item");

    WebElement price = fields.get(1);
    price.clear();
    price.sendKeys("1.0");

    WebElement stock = fields.get(2);
    stock.clear();
    stock.sendKeys("2");

    WebElement combo = form.findElement(By.className("v-filterselect-input"));
    String availability = combo.getAttribute("value");

    form.findElement(By.className("primary")).click();

    Collection<Product> allProducts = dataService.getAllProducts();
    $(GridElement.class).first().scrollToRow(allProducts.size());
    List<WebElement> rows = getRows();

    WebElement beforeLast = rows.get(rows.size() - 2);
    List<WebElement> columns = beforeLast.findElements(By.tagName("td"));
    Assert.assertFalse(hasText(columns.get(1), "New item"));

    WebElement last = rows.get(rows.size() - 1);
    columns = last.findElements(By.tagName("td"));
    Assert.assertTrue(hasText(columns.get(1), "New item"));
    Assert.assertTrue(hasText(columns.get(2), "1.0"));
    Assert.assertTrue(hasText(columns.get(3), availability.toUpperCase(Locale.ENGLISH)));
    Assert.assertTrue(hasText(columns.get(4), "2"));
}

From source file:com.vaadin.framework8.samples.SpringCrudIT.java

License:Apache License

@Test
public void initiallyDisabledButtonInEditor() {
    doLogin();/*from   w  w  w  .  ja v  a  2  s .co  m*/

    // select a row
    getRows().get(0).findElement(By.tagName("td")).click();

    WebElement form = findElement(By.className("product-form"));
    List<WebElement> buttons = form.findElements(By.className("v-button"));
    Assert.assertTrue(isDisabled(buttons.get(0)));
    Assert.assertTrue(isDisabled(buttons.get(1)));
}

From source file:com.vaadin.framework8.samples.SpringCrudIT.java

License:Apache License

@Test
public void changeProductNameToValid_bothButtonsAreEnabled() {
    doLogin();// w w  w  .  j  a v  a  2s . c  o  m

    getRows().get(0).findElement(By.tagName("td")).click();

    WebElement form = findElement(By.className("product-form"));

    List<WebElement> fields = form.findElements(By.className("v-textfield"));

    WebElement productName = fields.get(0);
    productName.clear();
    productName.sendKeys("Updated Product Name");
    productName.sendKeys(Keys.TAB);

    List<WebElement> buttons = form.findElements(By.className("v-button"));
    Assert.assertFalse(isDisabled(buttons.get(0)));
    Assert.assertFalse(isDisabled(buttons.get(1)));
}

From source file:com.vaadin.framework8.samples.SpringCrudIT.java

License:Apache License

@Test
public void changeProductNameToInvalid_saveIsDisabledAndDiscardIsEnabled() {
    doLogin();/*  ww w  .j  a v  a2s. co m*/

    getRows().get(0).findElement(By.tagName("td")).click();

    WebElement form = findElement(By.className("product-form"));

    List<WebElement> fields = form.findElements(By.className("v-textfield"));

    WebElement productName = fields.get(0);
    productName.clear();
    productName.sendKeys("a");
    productName.sendKeys(Keys.TAB);

    List<WebElement> buttons = form.findElements(By.className("v-button"));
    Assert.assertTrue(isDisabled(buttons.get(0)));
    Assert.assertFalse(isDisabled(buttons.get(1)));
}

From source file:com.vaadin.spring.framework7.samples.SpringNavigationIT.java

License:Apache License

private void checkErrorIndicator(WebElement element, boolean shouldBePresent) {
    boolean present = !element.findElements(By.className("v-errorindicator")).isEmpty();
    Assert.assertEquals("Error indicator", shouldBePresent, present);
}

From source file:com.vaadin.testbench.customelements.CheckBoxGroupElement.java

License:Apache License

public List<String> getOptionsIconUrls() {
    List<String> icons = new ArrayList<>();
    List<WebElement> options = findElements(byButtonSpan);
    for (WebElement option : options) {
        List<WebElement> images = option.findElements(By.tagName("img"));
        if (images != null && images.size() > 0) {
            icons.add(images.get(0).getAttribute("src"));
        } else {/*  w w  w.  java  2s  .  co m*/
            icons.add(null);
        }

    }
    return icons;
}

From source file:com.vaadin.testbench.elements.ButtonElement.java

License:Apache License

private boolean tryClickChild(WebElement e) {
    List<WebElement> children = e.findElements(By.xpath(".//*"));
    for (WebElement c : children) {
        if (c.isDisplayed()) {
            c.click();//from  w  w w  . j  a  v  a  2  s .com
            return true;
        } else {
            if (tryClickChild(c)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.vaadin.testbench.elements.ComboBoxElement.java

License:Apache License

/**
 * Gets the elements of all suggestions on the current page.
 * <p>/*from w w  w  . j  av a  2s  . c o  m*/
 * Opens the popup if not already open.
 *
 * @return a list of elements for the suggestions on the current page
 */
public List<WebElement> getPopupSuggestionElements() {
    List<WebElement> tables = getSuggestionPopup().findElements(By.tagName("table"));
    if (tables == null || tables.isEmpty()) {
        return Collections.emptyList();
    }
    WebElement table = tables.get(0);
    return table.findElements(By.tagName("td"));
}

From source file:com.vaadin.testbench.elements.MenuBarElement.java

License:Apache License

private boolean isSelectedTopLevelItem(WebElement item) {
    WebElement selectedItem = getSelectedTopLevelItem();
    if (selectedItem == null) {
        return false;
    }//  w w w  .j a va 2 s. com

    String itemCaption = item.findElements(By.className("v-menubar-menuitem-caption")).get(0)
            .getAttribute("innerHTML");
    String selectedItemCaption = selectedItem.findElements(By.className("v-menubar-menuitem-caption")).get(0)
            .getAttribute("innerHTML");
    return itemCaption.equals(selectedItemCaption);
}

From source file:com.vaadin.testbench.elements.MenuBarElement.java

License:Apache License

private boolean hasSubmenu(WebElement item) {
    List<WebElement> submenuIndicatorElements = item.findElements(By.className("v-menubar-submenu-indicator"));
    return submenuIndicatorElements.size() != 0;
}