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

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

Introduction

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

Prototype

public static ExpectedCondition<Boolean> textToBePresentInElementLocated(final By locator, final String text) 

Source Link

Document

An expectation for checking if the given text is present in the element that matches the given locator.

Usage

From source file:ExperimentRunner.java

License:Apache License

protected void runExperiment(String url, Hashtable<String, ArrayList<String>> store) {
    driver.get(url);/*  w  w  w .  ja  v  a 2  s .  c  o m*/
    // for octane, if an element with id="jit_final_result" contains text "===experiment done==="
    new WebDriverWait(driver, maxWaitTime).until(ExpectedConditions
            .textToBePresentInElementLocated(By.id("jit_final_result"), "===experiment done==="));
    System.out.println("text found in element");
    String expResult = driver.findElement(By.id("jit_final_result")).getAttribute("innerHTML");
    System.out.println(expResult);
    processRecordConsoleOutput(expResult, store);
}

From source file:bi.com.seleniumgrid.PhantomJsTest.java

License:Apache License

@Test
public void test() {
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    // Configure our WebDriver to support JavaScript and be able to find the PhantomJS binary
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("takesScreenshot", false);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_BINARY);
    final WebDriver driver = new PhantomJSDriver(capabilities);
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    pageTitle = driver.getTitle().trim();
    Assert.assertEquals(pageTitle, "GoalQuest");

    System.out.println("Page title is: " + driver.getTitle());

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

public void waitForTextPresent(final By by, final String text) throws Exception {
    waitForElementVisible(by);// w  ww  . j a v a2s.  c  om
    waitUntil(ExpectedConditions.textToBePresentInElementLocated(by, text));
}

From source file:com.asiainfo.tfsPlatform.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementtext, timeout./*from  ww  w.j  a v  a  2 s  .c  o  m*/
 */
public void waitForTextPresent(By by, String text) {
    waitForCondition(ExpectedConditions.textToBePresentInElementLocated(by, text), DEFAULT_WAIT_TIME);
}

From source file:com.asiainfo.tfsPlatform.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementtext, timeout??.// ww w  . jav a 2  s.  c  o  m
 */
public void waitForTextPresent(By by, String text, int timeout) {
    waitForCondition(ExpectedConditions.textToBePresentInElementLocated(by, text), timeout);
}

From source file:com.daarons.transfer.UploadTask.java

License:Apache License

private boolean isTransferButtonWithTextAvailable(String text, WebDriverWait wait) {
    return wait/* w  w w.  j a  v a  2s. com*/
            .until(ExpectedConditions.textToBePresentInElementLocated(By.className("transfer__button"), text));
}

From source file:com.daarons.transfer.UploadTask.java

License:Apache License

private boolean isLinkAvailable(WebDriverWait wait) {
    //checks to see if the download link is ready
    boolean isLinkAvailable;
    try {/*from   w ww.j  ava2s  . c  om*/
        isLinkAvailable = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(
                "body > div > div > div.transfer.transfer--half-panel > div > div.transfer__contents > p"),
                "Copy your download link:"));
    } catch (org.openqa.selenium.TimeoutException ex) {
        log.error("The download link for the file could not be found", ex);
        isLinkAvailable = false;
    }
    return isLinkAvailable;
}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2E.java

License:Apache License

private boolean checkVideoPlaying(BrowserUser user, WebElement videoElement, String containerQuerySelector) {

    // Video element should be in 'readyState'='HAVE_ENOUGH_DATA'
    user.getWaiter().until(ExpectedConditions.attributeToBe(videoElement, "readyState", "4"));

    // Video should have a valid 'src' value
    user.getWaiter().until(ExpectedConditions.attributeToBeNotEmpty(videoElement, "src"));

    // Video should have a srcObject (type MediaStream) with the attribute 'active' to true
    Assert.assertTrue((boolean) user.runJavascript("return document.querySelector('" + containerQuerySelector
            + "').getElementsByTagName('video')[0].srcObject.active"));

    // Video should trigger 'playing' event
    user.runJavascript("document.querySelector('" + containerQuerySelector
            + "').getElementsByTagName('video')[0].addEventListener('playing', window.MY_FUNC('"
            + containerQuerySelector + "'));");

    user.getWaiter().until(/*from   w  w  w .  ja v a 2s. c o m*/
            ExpectedConditions.textToBePresentInElementLocated(By.id("video-playing-div"), "VIDEO PLAYING"));
    user.runJavascript("document.body.removeChild(document.getElementById('video-playing-div'))");

    return true;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element has a text./*  w w w . j a v a  2s.co  m*/
 *
 * @param text           Text of Element
 * @param timeoutSec     seconds to wait until element has a text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForText(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isPresent;
    logAction(this, getParentClassName(), format("waitForText[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text));
        getText();
        isPresent = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                return getDriver().findElement(avatar.byLocator).getText().equals(text);
            }
        });
    } catch (TimeoutException e) {
        logTechnical(format("waitForText: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isPresent,
                format("waitForText - '%s' should has a text '%s'", getName(), text), takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element contains a text./*from   w  ww.j  a v a2 s.  c  o m*/
 *
 * @param text           Text of Element
 * @param timeoutSec     seconds to wait until element contains a text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForTextContains(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isPresent;
    logAction(this, getParentClassName(), format("waitForTextContains[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    final WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isPresent = wait.until(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text));
    } catch (TimeoutException e) {
        logTechnical(format("waitForTextContains: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isPresent,
                format("waitForTextContains - '%s' should has a text contains '%s'", getName(), text),
                takePassedScreenshot);
    }
    return parent;
}