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:be.ugent.mmlab.webdriver.Demo.java

License:Apache License

public void demoTime() throws InterruptedException {
    // initialize web browser.
    WebDriver driver = new FirefoxDriver();

    // go to the Belgian railways website
    driver.get("http://www.belgianrail.be");

    // select "English"
    // HTML:/*from   www  .  j ava  2  s . c o m*/
    // <a
    //   id="ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"
    //   href="javascript:__doPostBack('ctl00$bodyPlaceholder$languagesList$ctl02$languageNameLink','')"
    // > English </a>
    WebElement english = driver
            .findElement(By.id("ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"));
    english.click();

    // fill out departure
    WebElement from = driver.findElement(By.id("departureStationInput"));
    from.sendKeys("Gent-Dampoort");

    // pause for a second to make it not too fast
    Thread.sleep(1000);
    // click in the field to get the auto-completion away
    from.click();

    // fill out arrival
    WebElement to = driver.findElement(By.id("arrivalStationInput"));
    to.sendKeys("Brussel-Noord");

    Thread.sleep(1000);
    to.click();

    // click timetable button
    WebElement timetableButton = driver.findElement(By.id(
            "ctl00_ctl00_bodyPlaceholder_bodyPlaceholder_mobilityTimeTableSearch_HomeTabTimeTable1_submitButton"));
    timetableButton.click();

    // get departure info
    // HTML:
    // <td headers="hafasOVTimeOUTWARD" class="time">
    //    <div>
    //     <div class="planed overviewDep">
    //      10:00 dep <span class="bold prognosis">+12 min.</span>
    //     </div>
    //     <div class="planed">
    //      11:20 arr <span class="bold green">+0 min.</span>
    //     </div>
    //   </div>
    // </td>
    List<WebElement> timeCells = driver.findElements(By.className("time"));
    for (WebElement timeCell : timeCells) {
        List<WebElement> times = timeCell.findElements(By.className("planed"));
        System.out.println("----------------------------------------------");
        System.out.println("departure time: " + times.get(0).getText());
        System.out.println("arrival time:   " + times.get(1).getText());
    }
}

From source file:bi.meteorite.pages.SaikuTable.java

License:Apache License

private boolean hasMatchingCellValuesIn(WebElement firstRow, List<String> headings) {
    String html = firstRow.getAttribute("innerHTML");
    List<WebElement> cells = firstRow.findElements(By.xpath("//td | //th"));
    for (int cellIndex = 0; cellIndex < headings.size(); cellIndex++) {
        if ((cells.size() < cellIndex) || (!cells.get(cellIndex).getText().equals(headings.get(cellIndex)))) {
            return false;
        }// w  ww . ja v  a2  s.c  o  m
    }
    return true;
}

From source file:bi.meteorite.pages.SaikuTable.java

License:Apache License

private List<WebElement> cellsIn(WebElement row) {
    return row.findElements(By.xpath("./td | ./th"));
}

From source file:bodega.test.selenium.BodegaTest.java

@Test
public void testCrearBodega() throws Exception {
    webDriver.findElement(By.xpath("//button[contains(@id, 'createButton')]")).click();
    Thread.sleep(2000);//from  w w  w .  j a va 2s  .  c  o  m

    webDriver.findElement(By.id("name")).clear();
    webDriver.findElement(By.id("name")).sendKeys("NuevaBodega");

    webDriver.findElement(By.xpath("//button[contains(@id, 'saveButton')]")).click();
    Thread.sleep(2000);
    List<WebElement> table = webDriver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean good = false;
    for (WebElement webElement : table) {
        List<WebElement> elements = webElement.findElements(By.xpath("td"));
        for (WebElement elemento : elements) {
            if (elemento.getText().equals("NuevaBodega"))
                good = true;
        }
    }

    assertTrue(good);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebAutoComplete.java

License:Open Source License

/**
 * Busca nas tags <li> ou <td> filhas de "element", um texto correspondente a 
 * "value" na lista do autocomplete e seleciona-o
 * //from  ww w .  java2  s.  com
 * @param WebElement element Elemento pai da lista de resultados do autocomplete
 * @param String value valor a ser procurado na lista
 */
protected void selectOnList(WebElement element, String value) {

    List<WebElement> elementValue = element.findElements(By.tagName("li"));
    if (elementValue.size() == 0) {
        elementValue = element.findElements(By.tagName("td"));
    }

    for (WebElement item : elementValue) {
        if (item.getText().equals(value)) {
            // Aguarda o segundo elemento ser clicvel
            try {
                item.click();
            } catch (Throwable t) {
                waitElement(1);
                item.click();
            }
            break;
        }
    }
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.table.SeleniumTable.java

License:Apache License

/**
 * Generic method to take line cells of a tbody, thead or tfoot structure and returns as a List<List<Cell>>.
 * @param type/* w w w  . j ava2s  . c  om*/
 * @return List<List<Cell>>
 */
private List<List<Cell>> getAllCellsByLine(CellType type) {

    String locatorLines = "", locatorColumn = "";

    switch (type) {
    case HEAD:
        locatorLines = ".//thead/tr";
        locatorColumn = ".//th";
        break;
    case BODY:
        locatorLines = ".//tbody/tr";
        locatorColumn = ".//td";
        break;
    case FOOT:
        locatorLines = ".//tfoot/tr";
        locatorColumn = ".//td";
        break;
    }

    List<WebElement> lines = this.getElement().findElements(By.xpath(locatorLines)); // Recover all lines from the table

    List<List<Cell>> cellLines = new ArrayList<List<Cell>>(); // List of lines of the table

    Integer lineIndex = 1;

    for (WebElement line : lines) { // iterate the lines taken from table

        List<Cell> cellColumns = new ArrayList<Cell>();
        List<WebElement> columns = line.findElements(By.xpath(locatorColumn)); // Recover all columns from the lines
        Integer columnIndex = 1;

        for (WebElement column : columns) { // iterate the columns taken from the line
            Cell cell = new SeleniumCell(column);
            cell.setCoordinates(lineIndex, columnIndex);
            cellColumns.add(cell);
            columnIndex++;
        } // end of columns iteration

        cellLines.add(cellColumns);
        lineIndex++;
    } // end of lines iteration

    return cellLines;
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.WebDriverAdapter.java

License:Apache License

@Override
public List<WebElement> findElements(final By by) {

    // It's instanced a html element to reuse the findElements of WebElementAdapter      
    WebElement html = this.driver.findElement(By.tagName("html"));
    WebElement htmlAdapter = new WebElementAdapter(html, null, By.tagName("html"));

    return htmlAdapter.findElements(by);
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java

License:Apache License

/** {@inheritDoc}
 * <p> The method using the elements matched by findElements must implement a catch for 
 * StaleElementReferenceException, because if a AJAX reloads one of the elements, the
 * exceptions is not solved by WebElementAdapter.*/
@Override/*from  ww w .  j  a v  a  2  s  .c  o m*/
public List<WebElement> findElements(final By by) {

    return (List<WebElement>) (new StaleExceptionResolver<List<WebElement>>() {
        @Override
        public List<WebElement> execute(WebElement element) {
            List<WebElement> elements = new ArrayList<WebElement>(); // create
            // a
            // new
            // list
            // of
            // WebElements
            for (WebElement webElement : element.findElements(by)) {
                // encapsule the WebElements inside of a WebElementAdapter
                elements.add(new WebElementAdapter(webElement, thisObject, by, false));
            } // end for
            return elements;
        }// end execute
    }).waitForElement();
}

From source file:budget.WebDriverManager.java

private static void runQueryWF(WebDriver driver, WebDriverWait wait, int account) {
    String date;/* w ww. j  a va 2 s .c o m*/
    String Analytics;
    String Category;
    Double amount;
    String accountName = getAccountName(stmt, account);

    //Selecting and wait for certain account page
    if (account != 4) {
        new Select(driver.findElement(By.id("accountDropdown"))).selectByIndex(account - 4);
        driver.findElement(By.name("accountselection")).click();
    }
    wait.until(ExpectedConditions.textToBePresentInElement(driver.findElement(By.className("moremarginbottom")),
            accountName));

    //Gatherng total amount
    if (account == 6) {
        String limitStr = driver.findElement(By.xpath("//table[@id='balancedetailstable']/tbody/tr/td"))
                .getText();
        String balanceStr = driver.findElement(By.xpath("//table[@id='balancedetailstable']/tbody/tr[3]/td"))
                .getText();
        //amount = convertStringAmountToDouble(balanceStr) - convertStringAmountToDouble(limitStr);
        amount = convertStringAmountToDouble(balanceStr); //just for SECURE CARD
    } else {
        amount = convertStringAmountToDouble(
                driver.findElement(By.className("availableBalanceTotalAmount")).getText());
    }
    addTotal(stmt, getTimestamp(), account, amount, taLog);

    //Gathering transactinos
    if (account == 6) {
        String strAmount;
        driver.findElement(By.id("a.creditcardtempauth")).click();
        waitForElement(wait, By.xpath("//tbody[@id='tempAuthSection']/tr"));
        List<WebElement> rows = driver.findElements(By.xpath("//tbody[@id='tempAuthSection']/tr"));
        for (WebElement row : rows) {
            if (!"You have no temporary authorizations for this account.".equals(row.getText())) {
                date = rotateDate(row.findElement(By.className("rowhead")).getText(), "mm/dd/yy");
                Analytics = prepareTextForQuery(row.findElement(By.className("text")).getText());
                strAmount = row.findElements(By.className("amount")).get(0).getText();
                if ("+".equals(strAmount.substring(0, 1))) {
                    amount = convertStringAmountToDouble(strAmount);
                } else {
                    amount = -convertStringAmountToDouble(strAmount);
                }
                addTransaction(true, stmt, date, account, "", Analytics, amount, true, taLog);
            }
        }
        rows = driver.findElements(By.xpath("//table[@id='CreditCardTransactionTable']/tbody[4]/tr"));
        for (WebElement row : rows) {
            if (row.findElements(By.className("rowhead")).size() == 1) {
                if (!"".equals(row.findElement(By.className("rowhead")).getText())) {
                    date = rotateDate(row.findElement(By.className("rowhead")).getText(), "mm/dd/yy");
                    WebElement cell = row.findElement(By.className("text"));
                    Analytics = prepareTextForQuery(cell.findElement(By.xpath("span")).getText());
                    strAmount = row.findElements(By.className("amount")).get(0).getText();
                    if ("+".equals(strAmount.substring(0, 1))) {
                        amount = convertStringAmountToDouble(strAmount);
                    } else {
                        amount = -convertStringAmountToDouble(strAmount);
                    }
                    if (amount > 0) {
                        Category = "";
                    } else {
                        cell.findElement(By.className("detailsSection")).click();
                        waitForElement(wait, By.xpath("//table[@id='expandCollapseTable']/tbody/tr[2]/td[2]"));
                        Category = cell
                                .findElement(By.xpath("//table[@id='expandCollapseTable']/tbody/tr[2]/td[2]"))
                                .getText();
                    }
                    addTransaction(true, stmt, date, account, Category, Analytics, amount, false, taLog);
                }
            }
        }
    } else {
        driver.findElement(By.id("timeFilter")).click();
        new Select(driver.findElement(By.id("timeFilter"))).selectByVisibleText("Date Range");
        waitAndClick(driver, wait, By.name("Submit"));

        int itemsOnPage;
        if (driver.findElements(By.className("emdisclosure")).size() == 1) {
            itemsOnPage = Integer.parseInt(driver.findElement(By.className("emdisclosure")).getText()
                    .replace("(", "").replace(" transactions per page)", ""));
        } else {
            itemsOnPage = 0;
        }
        int itemsCounter;
        Boolean isPending = false;
        List<WebElement> lstAmounts;
        do {
            itemsCounter = 0;
            List<WebElement> rows = driver
                    .findElements(By.xpath("//table[@id='DDATransactionTable']/tbody/tr"));
            for (WebElement row : rows) {
                if (row.findElement(By.className("text")).getText().contains("Pending transactions")) {
                    isPending = true;
                }
                if (row.findElement(By.className("text")).getText().contains("Posted Transactions")) {
                    isPending = false;
                }

                if (row.findElements(By.className("rowhead")).size() == 1) {
                    date = rotateDate(row.findElement(By.className("rowhead")).getText(), "mm/dd/yy");
                    Analytics = prepareTextForQuery(row.findElement(By.className("text")).getText());
                    lstAmounts = row.findElements(By.className("amount"));
                    if (!" ".equals(lstAmounts.get(0).getText())) {
                        amount = convertStringAmountToDouble(lstAmounts.get(0).getText());
                    }
                    if (!" ".equals(lstAmounts.get(1).getText())) {
                        amount = -convertStringAmountToDouble(lstAmounts.get(1).getText());
                    }

                    addTransaction(true, stmt, date, account, "", Analytics, amount, isPending, taLog);
                    itemsCounter++;
                }
            }
            if (itemsCounter == itemsOnPage) {
                driver.findElement(By.linkText("Next >")).click();
            }
        } while (itemsCounter == itemsOnPage);
    }
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

boolean verifyFolderSize(int rowNum) throws Exception {
    List<WebElement> tableRows = beaconTable.findElements(By.tagName("tr"));
    WebElement selectedRow = tableRows.get(rowNum);
    List<WebElement> columns = selectedRow.findElements(By.tagName("td"));
    String sizeString = columns.get(2).getText();
    return sizeString != null;
}