Example usage for org.openqa.selenium.support.ui Wait until

List of usage examples for org.openqa.selenium.support.ui Wait until

Introduction

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

Prototype

<T> T until(Function<? super F, T> isTrue);

Source Link

Document

Implementations should wait until the condition evaluates to a value that is neither null nor false.

Usage

From source file:com.tractionsoftware.reshoot.teampage.ProteusPage.java

License:Apache License

public void waitForClassName(int timeoutSeconds, final String className) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeoutSeconds, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override/*  ww w  .  j  a v  a2  s .c  o m*/
        public WebElement apply(WebDriver driver) {
            return driver.findElement(By.className(className));
        }
    });
}

From source file:com.tractionsoftware.reshoot.teampage.ProteusPage.java

License:Apache License

public void waitForClassName(int timeoutSeconds, final String className, WebElement scope) {
    Wait<WebElement> wait = new FluentWait<WebElement>(scope).withTimeout(timeoutSeconds, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(new Function<WebElement, WebElement>() {
        @Override/*  w w w  .ja v  a 2  s . com*/
        public WebElement apply(WebElement scope) {
            return scope.findElement(By.className(className));
        }
    });
}

From source file:com.tractionsoftware.reshoot.util.TractionWebdriverUtils.java

License:Apache License

public static WebElement waitForElement(WebDriver driver, final By by, int seconds) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(seconds, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    WebElement elm = wait.until(new Function<WebDriver, WebElement>() {
        @Override//from  w  w  w .ja v a2  s .c  o m
        public WebElement apply(WebDriver driver) {
            return driver.findElement(by);
        }
    });
    return elm;
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * internal method which actually checks whether the given element is
 * exists.//from  ww  w  .j a va  2 s.  c o  m
 * 
 * @param searchPath
 *            the search path
 * @return the web element
 * @throws Exception
 *             the exception
 */
private WebElement checkElementPresence(final String searchPath) throws Exception {
    WebDriver driver = getDriver();
    WebElement webElement = null;
    String locator = searchPath;
    final Logger log = getLog();
    int count = getRetryCount();
    setCommandStartTime(getCurrentTime());
    final By searchBy = getLocatorType(locator);
    final Long retryMillis = 1000L;

    try {

        Function<WebDriver, WebElement> findElementFunction = new FindElementFunction<WebDriver, WebElement>(
                searchBy);

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout((count * retryMillis), TimeUnit.MILLISECONDS)
                .pollingEvery(retryInterval, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class)
                .ignoring(WebDriverException.class);

        webElement = wait.until(findElementFunction);

    } catch (Exception e) {
        log.error("Element [ " + searchPath + " ] Not Found", e);
    }

    if (webElement != null) {
        try {
            log.info("Element [ " + searchBy.toString() + " ] Found");
            JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
            jsExecutor.executeScript("arguments[0].scrollIntoView(false);", webElement);
        } catch (Exception ex) {
            log.error("Exception occured while scrolling to the element.", ex);
        }
    } else {
        throw new Exception("Element " + searchPath);
    }

    return webElement;
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitForTextPresent(final String text) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, WAITFOR_TIMEOUT / 1000);
    wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver webDriver) {
            return selenium.isTextPresent(text);
        }/*  w  w  w . j  ava  2s . com*/
    });
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitForVariable(final String variable, final boolean inverse) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, WAITFOR_TIMEOUT / 1000);
    wait.until(new ExpectedCondition<Object>() {
        public Object apply(WebDriver webDriver) {
            JavascriptExecutor executor = (JavascriptExecutor) webDriver;
            return executor.executeScript("var r = " + variable + " !== undefined && " + variable
                    + " !== null && " + variable + " !== false; return " + (inverse ? "!" : "") + "r");
        }/*w w  w .  ja v  a  2 s . co m*/
    });
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public WebElement waitForElement(final By by, long timeout) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, timeout / 1000, 250).ignoring(RuntimeException.class);
    return wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitAndClick(By by) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, WAITFOR_TIMEOUT / 1000, 250)
            .ignoring(RuntimeException.class);
    wait.until(ExpectedConditions.elementToBeClickable(by));
    click(by);//ww  w  .  j a  va  2 s  .c om
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitForElementToDisappear(final By by) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, WAITFOR_TIMEOUT / 1000, WAITFOR_INTERVAL)
            .ignoring(RuntimeException.class);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitForCondition(final String condition, long timeout) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, timeout / 1000);
    wait.until(new ExpectedCondition<Object>() {
        public Object apply(WebDriver webDriver) {
            return ((JavascriptExecutor) webDriver).executeScript(condition);
        }/*  ww w.  j  av  a  2  s .co  m*/
    });
}