Example usage for org.openqa.selenium WebElement getText

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

Introduction

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

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

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

License:Open Source License

/**
 * Mtodo generalizado para selecionar o valor do select (DropDown)
 * /*  ww  w.  j a v a  2  s .  c  om*/
 * @param value
 * @param type
 */
private void select(String value, WebSelectType type) {

    // Aguarda o primeiro elemento ser clicvel
    waitElement(0);

    List<WebElement> elements = getElements();

    if (elements.get(0).getTagName().equals("select")) {

        // Select comum e usa um helper do selenium
        org.openqa.selenium.support.ui.Select lSelect = new org.openqa.selenium.support.ui.Select(
                elements.get(0));

        // Verifica o tipo valor do select
        if (type == WebSelectType.TEXT) {
            lSelect.selectByVisibleText(value);
        } else if (type == WebSelectType.INDEX) {
            lSelect.selectByIndex(Integer.parseInt(value));

            // Soluo de contorno para atualizar o valor selecionado
            lSelect.getFirstSelectedOption();
        } else if (type == WebSelectType.VALUE) {
            lSelect.selectByValue(value);
        }

    } else {

        // Outros tipos de select como a do primefaces
        elementMain = elements.get(0);
        elementMain.click();

        // Tempo do efeito de abertura das opes
        waitElementOnlyVisible(1);

        List<WebElement> elementValue = elements.get(1).findElements(By.tagName("li"));

        // Aguarda o segundo elemento ser clicvel
        if (type == WebSelectType.INDEX) {
            // ?ndice comeando em 1 - Muitas vezes o 1  o item SELECIONE
            int index = 1;
            for (WebElement item : elementValue) {
                if (index++ == Integer.valueOf(value)) {
                    itemListClick(item);
                    break;
                }
            }
        } else {
            for (WebElement item : elementValue) {
                // Verifica se existe a virgula, se existir significa que
                // so multiplos valores e procura por contains
                if (value.contains(",")) {
                    if (!item.getText().equals("") && value.contains(item.getText())) {
                        itemListClick(item);

                        item = null;
                        continue;
                    }
                } else if (item.getText().equals(value)) {
                    itemListClick(item);
                    break;
                }
            }
        }

        // Aguarda o DIV sumir se no for seleo multipla, pois na seleo
        // multipla ele tem o boto de fechar
        if (!value.contains(","))
            waitInvisible(1);

    }

}

From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.form.SeleniumSelectField.java

License:Apache License

@Override
public final List<Option> getOptions() {

    SeleniumOption option;/*from w  ww .  ja  v a2  s  .c  o  m*/
    reloadElement();
    List<WebElement> webElements = getElement().findElements(By.tagName("option"));
    for (WebElement element : webElements) {
        option = new SeleniumOption();
        option.setIndex(Integer.valueOf(element.getAttribute("index")));
        option.setValue(element.getAttribute("value"));
        option.setText(element.getText());
        option.webElement = element;
        options.add(option);
    }
    return this.options;
}

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

License:Apache License

@Override
public String getText() {
    return new StaleExceptionResolver<String>() {
        @Override/*from w  w w.j  a  v  a 2  s  .c  om*/
        public String execute(WebElement element) {
            return element.getText();
        }
    }.waitForElement();
}

From source file:bst.cpo.automation.dm.actions.Settings_Actions.java

public void My_Profile_Elements() throws InterruptedException {
    //Looks like this just returns the first element found with the name.
    WebElement element = DMDriver.findElement(By.className("pure-control-group"));
    logThis(element.getText());
    logThis("===========");
    //While this print out each individually.
    //TODO - find away to loop through without specifically doing each index?
    List<WebElement> we2 = DMDriver.findElements(By.className("pure-control-group"));
    logThis("(0)=" + we2.get(0).getText());
    logThis("(1)=" + we2.get(1).getText());
    logThis("(2)=" + we2.get(2).getText());
    logThis("(3)=" + we2.get(3).getText());
}

From source file:budget.WebDriverManager.java

private static void runQueryWF(WebDriver driver, WebDriverWait wait, int account) {
    String date;/*from   w ww. jav a  2  s. com*/
    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:businessFramework.module.gibddMedicalExamination.modals.patientModel.PatientModelModal.java

/**
 * ? ?   af-type-date//w  w  w.j  ava2s. com
 */
public void selectAfTypeDate(String value) {
    for (WebElement option : getOptions()) {
        if (option.getText().equals(value)) {
            click(option);
            break;
        }
    }
}

From source file:ca.nrc.cadc.search.integration.AbstractSearchFormPage.java

License:Open Source License

void verifyFormInputMessage(final String inputID, final boolean errorExpected, final String expectedMessage)
        throws Exception {
    if (errorExpected) {
        verifyFormInputError(inputID);/*  w ww.  j  a  v a  2  s  .c om*/
    }

    final By contents = By.xpath(String.format(CONTENT_LOCATOR_XPATH, (inputID + "_details")));

    if (!Objects.equals(expectedMessage, "")) {
        waitForTextPresent(contents, expectedMessage);
    } else {
        WebElement contentEl = find(contents);
        if (!contentEl.getText().equals("")) {
            throw new Exception();
        }
    }
}

From source file:ca.nrc.cadc.search.integration.SearchResultsPage.java

License:Open Source License

String getSelectedRestFrameEnergyUnit() throws Exception {
    final Select rfUnitSelect = new Select(gridContainer.findElement(REST_FRAME_ENERGY_UNIT_SELECT_LOCATOR));
    final WebElement rfUnitSelectedOption = rfUnitSelect.getFirstSelectedOption();

    return rfUnitSelectedOption.getText();
}

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

License:Open Source License

public void clickFolder(String folderName) {
    WebElement folder = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(
            xpath("//*[@id=\"beacon\"]/tbody/tr/td/a[text()[contains(.,'" + folderName + "')]]")));

    System.out.println("Folder to be clicked: " + folder.getText());
    folder.click();/*w w  w . j  a va 2  s . c o m*/
}

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

License:Open Source License

boolean verifyFolderName(int rowNum, String expectedValue) throws Exception {
    List<WebElement> tableRows = beaconTable.findElements(By.tagName("tr"));
    WebElement selectedRow = tableRows.get(rowNum);
    WebElement namecolumn = selectedRow.findElement(By.cssSelector("a:nth-of-type(1)"));
    System.out.println(namecolumn.getText());
    return expectedValue.equals(namecolumn.getText());

}