Example usage for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElement

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElement

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElement.

Prototype

public static ExpectedCondition<Boolean> textToBePresentInElement(final WebElement element, final String text) 

Source Link

Document

An expectation for checking if the given text is present in the specified element.

Usage

From source file:$.SimpleTest.java

License:Apache License

@Test
    public void testSimple() throws Exception {
        this.driver.get(this.serverUrl + "index.html");

        String whoToSend = "foo";

        WebElement who = this.driver.findElement(By.id("who"));
        who.sendKeys(whoToSend);//www.  j a va 2 s  . co  m

        WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
        sendBtn.click();

        // wait 5 secs for ajax response
        new WebDriverWait(this.driver, 5)
                .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

        WebElement response = this.driver.findElement(By.id("response"));
        String text = response.getText();

        Assert.assertEquals("Hello " + whoToSend, text);

    }

From source file:budget.WebDriverManager.java

private static void runQueryWF(WebDriver driver, WebDriverWait wait, int account) {
    String date;//  ww  w .  j a va2  s  . c om
    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:com.androidwhy.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementtext, timeout??.// w w w.  ja va2 s.  c o  m
 */
public void waitForTextPresent(By by, String text, int timeout) {
    waitForCondition(ExpectedConditions.textToBePresentInElement(by, text), timeout);
}

From source file:com.artnaseef.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testSimple() throws Exception {
    this.driver.get(this.serverUrl + "index.html");

    String whoToSend = "foo";

    WebElement who = this.driver.findElement(By.id("who"));
    who.sendKeys(whoToSend);//w  w w.  j a  v  a  2 s.  c  om

    WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
    sendBtn.click();

    // wait 5 secs for ajax response
    new WebDriverWait(this.driver, 5)
            .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

    WebElement response = this.driver.findElement(By.id("response"));
    String text = response.getText();

    Assert.assertEquals("Hello " + whoToSend, text);

}

From source file:com.codenvy.ide.pageObjects.ImportProxyObjects.java

License:Open Source License

/**
 * Insert details when importing the proxy
 * /*from  ww w.  j a  va2  s .co  m*/
 * @param fileName  proxy file
 * @param proxyLocation  save location
 * @throws Exception
 */
public void insertImportProxyDetails(String fileName, String proxyLocation) throws Exception {
    try {
        proxyFileElement.sendKeys(fileName);
        proxyLocationElement.sendKeys(proxyLocation);
    } catch (TimeoutException toe) {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.textToBePresentInElement(proxyFileElement, fileName));
        wait.until(ExpectedConditions.textToBePresentInElement(proxyLocationElement, proxyLocation));
    } catch (NoSuchElementException e) {
        log.error("Proxy Import field element not found", e);
    } catch (Exception e) {
        throw (e);
    }
}

From source file:com.codenvy.ide.pageObjects.NewProxyObjects.java

License:Open Source License

/**
 * Insert details when importing the proxy
 * @param proxyName Name of the proxy//from  w  w w  . j  a v a 2 s.c  o  m
 * @param proxyType Type of the proxy
 * @param proxyLocation save location
 * @throws Exception
 */
public void insertNewProxyDetails(String proxyName, String proxyType, String proxyLocation) throws Exception {
    try {
        proxyNameElement.sendKeys(proxyName);
        Select droplist = new Select(proxyTypeElement);
        droplist.selectByVisibleText(proxyType);
        proxyLocationElement.sendKeys(proxyLocation);
    } catch (TimeoutException toe) {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.textToBePresentInElement(proxyNameElement, proxyName));
        wait.until(ExpectedConditions.textToBePresentInElement(proxyTypeElement, proxyName));
        wait.until(ExpectedConditions.textToBePresentInElement(proxyLocationElement, proxyLocation));
    } catch (NoSuchElementException e) {
        log.error("Proxy Creation field element not found", e);
    } /*catch (Exception e) {
       throw (e);
      }*/
}

From source file:com.codenvy.ide.pageObjects.NewProxyObjects.java

License:Open Source License

/**
 * Insert the Endpoint URL//ww  w  .ja v a2  s  .co m
 * @param endpointURL URL of the endpoint
 * @throws Exception
 */
public void insertEndpointURL(String endpointURL) throws Exception {
    try {
        endpointURLElement.sendKeys(endpointURL);
    } catch (TimeoutException toe) {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.textToBePresentInElement(endpointURLElement, endpointURL));
    } catch (NoSuchElementException e) {
        log.error("Endpoint URL field element not found", e);
    } /* catch (Exception e) {
        throw (e);
      }*/
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForTextPresent(final HtmlElement element, final String text) {
    Assert.assertNotNull(text, "Text can't be null");
    TestLogging.logWebStep(null, "wait for text \"" + text + "\" to be present.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.textToBePresentInElement(element.getBy(), text));
}

From source file:com.iptv.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementtext, timeout.
 */
public void waitForTextPresent(By by, String text) {
    waitForCondition(ExpectedConditions.textToBePresentInElement(by, text), DEFAULT_WAIT_TIME);
}

From source file:com.liferay.blade.sample.test.functional.utils.BladeSampleFunctionalActionUtil.java

License:Apache License

public static boolean isTextPresent(WebDriver webDriver, WebElement webelement, String string) {

    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 30);

    try {//from www .j  a v  a 2  s.co m
        webDriverWait.until(ExpectedConditions.textToBePresentInElement(webelement, string));

        return true;
    } catch (org.openqa.selenium.TimeoutException te) {
        return false;
    }
}