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.mroza.seleniumTests.NewProgramsViewTests.NewProgramsViewPage.java

License:Open Source License

private WebElement getTextAreaNamed(String inputName) {
    WebElement tableWithInputFields = driver.findElement(By.tagName("table"));
    WebElement tableBody = tableWithInputFields.findElement(By.tagName("tbody"));
    List<WebElement> inputRows = tableBody.findElements(By.tagName("tr"));
    for (WebElement inputRow : inputRows) {
        if (inputRow.findElements(By.tagName("td")).get(0).getText().equals(inputName)) {
            return inputRow.findElements(By.tagName("td")).get(1).findElement(By.tagName("textArea"));
        }/* ww w .  jav a  2  s.co m*/
    }
    return null;
}

From source file:com.mroza.seleniumTests.ProgramDirectoryViewTests.ProgramDirectoryViewPage.java

License:Open Source License

public List<String> getAllProgramsSymbols() {
    List<WebElement> tableRows = getTableRows();
    List<String> programSymbolsList = new ArrayList<>();
    for (WebElement tableRow : tableRows) {
        List<WebElement> symbolsElement = tableRow.findElements(By.tagName("td"));
        WebElement symbolElement = symbolsElement.get(0);
        String programSymbol = symbolElement.getText();
        programSymbolsList.add(programSymbol);
    }// ww w. ja  va 2  s .c  o m
    return programSymbolsList;
}

From source file:com.mroza.seleniumTests.ProgramDirectoryViewTests.ProgramDirectoryViewPage.java

License:Open Source License

public void setLetterFilterValue(String buttonValue) {
    WebElement buttonsArea = driver.findElement(By.className("ui-selectonebutton"));
    List<WebElement> letterButtons = buttonsArea.findElements(By.className("ui-button"));
    for (WebElement letterButton : letterButtons) {
        String buttonTextValue = letterButton.findElement(By.className("ui-button-text")).getText();
        if (buttonTextValue.equals(buttonValue)) {
            letterButton.click();//from   w w  w. ja  va2  s  .  c  om
            break;
        }
    }
    SeleniumWaiter.waitForJQueryAndPrimeFaces(driver);
}

From source file:com.mroza.seleniumTests.ProgramDirectoryViewTests.ProgramDirectoryViewPage.java

License:Open Source License

public void clickDeleteProgramButtonForProgramWithSymbol(String programSymbol) {
    List<WebElement> tableRows = getTableRows();
    for (WebElement tableRow : tableRows) {
        List<WebElement> columns = tableRow.findElements(By.tagName("td"));
        if (columns.get(0).getText().equals(programSymbol)) {
            WebElement deleteButton = columns.get(3).findElement(By.tagName("button"));
            deleteButton.click();//w w w.  j  a v a  2 s  .  c  o  m
        }
    }
}

From source file:com.mroza.seleniumTests.ProgramDirectoryViewTests.ProgramDirectoryViewPage.java

License:Open Source License

private List<WebElement> getTableRows() {
    WebElement tableContent = driver.findElement(By.tagName("table"));
    WebElement tableBody = tableContent.findElement(By.tagName("tbody"));
    return tableBody.findElements(By.tagName("tr"));
}

From source file:com.mvnsnm.Tabviews.java

public void campaign() {

    WebElement tabhome = driver.findElement(By.xpath("//a[@id='ui-id-1']"));

    final String text_a = "Home";

    Assert.assertEquals(text_a, tabhome.getText());

    driver.findElement(By.id("ui-id-2")).click();

    driver.findElement(By.xpath("//input[@id='campname']")).sendKeys("Hello Test");

    WebElement select = driver.findElement(By.xpath("//select[@id='lstkeyword']"));

    List<WebElement> allOptions = select.findElements(By.tagName("option"));

    for (WebElement option : allOptions) {

        System.out.println(String.format("Value is: %s", option.getAttribute("value")));
        String optval = option.getAttribute("value");
        if (optval.equals("103")) {
            option.click();/*ww w.  j a  v  a2s . c  o  m*/
        }
    }
    //smsmessage  smssendtime  smssubmit
    WebElement msg = driver.findElement(By.xpath("//textarea[@id='smsmessage']"));

    msg.sendKeys("This message bodey was set from selenium automation and should save in db");

    WebElement sendtime = driver.findElement(By.xpath("//input[@id='smssendtime']"));

    sendtime.sendKeys("2015/02/04 10:30:00");

    WebElement submit = driver.findElement(By.xpath("//input[@id='smssubmit']"));

    submit.click();

    WebElement chweekly = driver.findElement(By.xpath("//input[@id='weekly']"));

    chweekly.click();

    WebElement monthslct = driver.findElement(By.xpath("//select[@id='weekofmonth']"));

    List<WebElement> weekopt = monthslct.findElements(By.tagName("option"));

    for (WebElement option : weekopt) {

        System.out.println(String.format("Value is: %s", option.getAttribute("value")));
        String optval = option.getAttribute("value");
        if (optval.equals("3")) {
            option.click();
        }
    }
    //createmoremsg
    WebElement weekmsg = driver.findElement(By.xpath("//textarea[@id='createmoremsg']"));

    weekmsg.sendKeys("This message bodey was set for weekly report and can be saved in db");

    //moremsgsave
    WebElement more_msg = driver.findElement(By.xpath("//input[@id='moremsgsave']"));

    more_msg.click();

    chweekly.click();

    WebElement monthly = driver.findElement(By.xpath("//input[@id='monthly']"));

    monthly.click();

    WebElement monthofyear = driver.findElement(By.xpath("//select[@id='monthofyear']"));

    List<WebElement> monthopt = monthofyear.findElements(By.tagName("option"));

    for (WebElement option : monthopt) {

        System.out.println(String.format("Value is: %s", option.getAttribute("value")));
        String optval = option.getAttribute("value");
        if (optval.equals("7")) {
            option.click();
        }
    }
    //createmoremsg
    WebElement monthlymsg = driver.findElement(By.xpath("//textarea[@id='monthlymsgmore']"));

    monthlymsg.sendKeys("This message bodey was set for weekly report and can be saved in db");

    //moremsgsave
    WebElement monthlymsgsave = driver.findElement(By.xpath("//input[@id='monthlymsgsave']"));

    monthlymsgsave.click();

    monthly.click();

}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test1() throws Exception {
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));
        Assert.assertThat(rows.size(), is(5));
        return true;
    });//from  ww  w. j ava 2s  .com
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test2() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.clear();/*from   w  w w  . j ava  2 s. c  o m*/
    element.sendKeys("2002");
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = table.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(2));
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test3() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys(Keys.BACK_SPACE);//from   w ww .  j  a  v a 2  s  .c  om
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = table.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(5));
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test4() throws Exception {
    WebElement sort = driver.findElement(By.id("h_year"));
    sort.click();//w w w  .  j a v a2s  .c  o m
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> sortedRows = table.findElements(By.tagName("tr"));
    String firstRow = sortedRows.get(0).findElements(By.tagName("td")).get(0).getText();
    String lastRow = sortedRows.get(4).findElements(By.tagName("td")).get(0).getText();
    Assert.assertThat(firstRow, is("938"));
    Assert.assertThat(lastRow, is("940"));
}