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:EditCarTest.java

private WebElement navigateToEditButton(WebElement rowElement) {
    return rowElement.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0);
}

From source file:EditCarTest.java

private WebElement navigateToCar(String carId) {
    WebElement tableOfCars = driver.findElement(By.id("tbodycars"));
    List<WebElement> carsList = tableOfCars.findElements(By.tagName("tr"));
    WebElement car = null;/*from   w  w w.jav a2s. co m*/
    for (int i = 0; i < carsList.size(); i++) {
        if (carsList.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase(carId)) {
            car = carsList.get(i);
            break;
        }
    }
    return car;
}

From source file:TestWithSelenium.java

@Test
public void tDomConstructedTableReady() {
    //searching for tbody
    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });/*from w  w w.  ja  v a 2 s.  co  m*/

    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(5));
}

From source file:TestWithSelenium.java

@Test
public void uTest2002Filter() {
    //searching for filter & sending key
    WebElement filter = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.id("filter"));
            });/*from   www  .j a  v a 2s. c o m*/
    filter.sendKeys("2002");

    //searching for tbody
    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });

    //checking whether number of rows is 2
    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(2));

}

From source file:TestWithSelenium.java

@Test
public void vTestClearFilter() {
    //searching for filter & sending key
    WebElement filter = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.id("filter"));
            });//w w  w .j a  v  a2s.c o  m

    filter.sendKeys(Keys.BACK_SPACE);

    //searching for tbody
    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });

    //checking whether number of rows is 5
    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(5));
}

From source file:TestWithSelenium.java

@Test
public void wTestSorting() {
    //searching for sort button
    WebElement sortButton = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.id("h_year"));
            });/*from w  ww .j  av  a2  s .co m*/
    sortButton.click();

    //searching for tbody
    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });

    //listing all tr
    List<WebElement> tableSorted = table.findElements(By.tagName("tr"));
    Assert.assertThat(tableSorted.get(0).findElements(By.tagName("td")).get(0).getText(), is("938"));
    Assert.assertThat(tableSorted.get(4).findElements(By.tagName("td")).get(0).getText(), is("940"));

}

From source file:TestWithSelenium.java

@Test
public void xTestEdit() {
    //searching for tbody
    List<WebElement> tableRows = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    WebElement editButton = null;
    for (int i = 0; i < tableRows.size(); i++) {
        if (tableRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = tableRows.get(i);
            break;
        }/*from w  w w .j  av a  2  s  . c  o m*/
    }

    editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0).click();
    WebElement element = driver.findElement(By.id("description"));
    element.clear();
    element.sendKeys("Cool car");
    driver.findElement(By.id("save")).click();

    //searching for new tbody
    List<WebElement> tableRowsUpdated = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    String descriptionNew = "";
    for (int i = 0; i < tableRowsUpdated.size(); i++) {
        if (tableRowsUpdated.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            descriptionNew = tableRowsUpdated.get(i).findElements(By.tagName("td")).get(5).getText();
            break;
        }
    }
    assertThat(descriptionNew, is("Cool car"));
}

From source file:TestWithSelenium.java

@Test
public void zAddNew() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");
    driver.findElement(By.id("save")).click();

    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });//from w w w. j a va 2s . c  o m
    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(6));

}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.TableTest.java

License:Apache License

private Integer getDiceValue(WebDriver driver) {
    String src = null;//w w  w .  ja v a2 s.  c om

    if (exists(driver, By.id(diceFormPrefix + "diceImage"))) {
        src = driver.findElement(By.id(diceFormPrefix + "diceImage")).getAttribute("src");
    } else if (exists(driver, By.id(diceFormPrefix + "dice"))) {
        WebElement diceElement = driver.findElement(By.id(diceFormPrefix + "dice"));
        src = diceElement.getAttribute("src");

        if (src == null) {
            List<WebElement> imgElems = diceElement.findElements(By.xpath(".//img"));

            if (!imgElems.isEmpty()) {
                diceElement = imgElems.get(0);
                src = diceElement.getAttribute("src");
            }
        }
    }

    if (src == null) {
        assertFalse(TestsuiteConstants.KNOWN_ERROR_PREFIX + " Could not retrieve dice value", true);
    }

    Matcher matcher = DICE_VALUE_PATTERN.matcher(src);

    if (!matcher.matches()) {
        assertFalse(TestsuiteConstants.KNOWN_ERROR_PREFIX + " Could not retrieve dice value", true);
    }

    return Integer.parseInt(matcher.group(1));
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I change the language to \"([^\"]*)\"$")
public void I_change_the_language_to(String language) throws Throwable {
    WebElement select = driver().findElement(By.id("switchLanguage"));
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.getText().contains(language)) {
            option.click();// w  w  w.ja  v  a 2 s .co m
            blur(By.id("switchLanguage"));
            break;
        }
    }
    jqueryWait();
}