Why doesn't my wait method wait until 30 seconds?

Viewed 220

Why doesn't my wait method wait until 30 seconds?

My method should timeout after 30seconds if the method cannot find the element, currently return true or false without any timeout, any ideas?

    public boolean WaitUntilWebElementIsVisiblePredicate(WebElement element) {
FluentWait<WebElement> wait = new FluentWait<WebElement>(element)
        .withTimeout(30, TimeUnit.SECONDS)
        .pollingEvery(100, TimeUnit.MILLISECONDS)
        .ignoring(NoSuchFieldException.class);

Function<WebElement, Boolean> f = new Function<WebElement, Boolean>() {
    @Override
    public Boolean apply(WebElement element) {
        if (!element.isDisplayed()) {
            System.out.println("Method failed: WaitUntilWebElementIsVisiblepPredicate, using locator: " + element.toString());
            return false;
        }
        System.out.println("Element visible, using method: WaitUntilWebElementIsVisiblepPredicate, Locator: " + element.toString());
        return true;                
    }
};
return wait.until(f);
}
1 Answers
Related