Example usage for org.openqa.selenium.support.ui FluentWait ignoring

List of usage examples for org.openqa.selenium.support.ui FluentWait ignoring

Introduction

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

Prototype

public FluentWait<T> ignoring(Class<? extends Throwable> exceptionType) 

Source Link

Usage

From source file:org.alfresco.po.PageElement.java

License:Open Source License

/**
 * Helper method to find a {@link WebElement} with a time limit in
 * milliseconds. During the wait period it will check for the element every
 * 100 millisecond. If the element is not displayed, refresh the page.
 *
 * @param by {@link By} criteria to search by
 * @return {@link WebElement}// w  w  w. j a v a2  s.c  o  m
 */
public WebElement findAndWaitWithRefresh(final By by, final long limit) {
    if (null == by) {
        throw new IllegalArgumentException("A search By criteria is required");
    }
    FluentWait<By> fluentWait = new FluentWait<By>(by);
    fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS);
    fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS);
    fluentWait.ignoring(NoSuchElementException.class);
    fluentWait.until(new Predicate<By>() {
        public boolean apply(By by) {
            try {
                return driver.findElement(by).isDisplayed();
            } catch (NoSuchElementException ex) {
                driver.navigate().refresh();
                return false;
            }
        }
    });
    return driver.findElement(by);
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

public static List<WebElement> findElementsWithTimeout(final By by) throws NoSuchElementException {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, List<WebElement>>() {
        @Override// w ww  . j  a  v  a2 s . c om
        public List<WebElement> apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            return elements.isEmpty() ? null : elements;
        }
    });
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait for an element to be present, checking every 100 ms.
 *
 * @since 5.7.2/*from w ww  .  ja v a 2  s.  co  m*/
 */
public static void waitUntilElementPresent(final By locator) {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    });
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait on a the given function, checking every 100 ms.
 *
 * @param function/*from   w w  w.j  a v a2 s . co m*/
 * @param ignoredExceptions the types of exceptions to ignore.
 * @since 5.9.2
 */
@SafeVarargs
public static <K extends java.lang.Throwable> void waitUntilGivenFunctionIgnoreAll(
        Function<WebDriver, Boolean> function, java.lang.Class<? extends K>... ignoredExceptions) {
    FluentWait<WebDriver> wait = getFluentWait();
    if (ignoredExceptions != null) {
        if (ignoredExceptions.length == 1) {
            wait.ignoring(ignoredExceptions[0]);
        } else {
            wait.ignoreAll(Arrays.asList(ignoredExceptions));
        }

    }
    wait.until(function);
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Fluent wait on a the given function, checking every 100 ms.
 *
 * @param function/*from w  w  w  .ja  v  a 2s .c  o m*/
 * @param ignoredException the type of exception to ignore.
 * @since 5.9.2
 */
public static <K extends java.lang.Throwable> void waitUntilGivenFunctionIgnoring(
        Function<WebDriver, Boolean> function, java.lang.Class<? extends K> ignoredException) {
    FluentWait<WebDriver> wait = getFluentWait();
    if (ignoredException != null) {
        wait.ignoring(ignoredException);
    }
    wait.until(function);
}