Webdriver FluentWait not ignoring exceptions

Viewed 16342

I have automated some user flows which go via this page http://www.efinancialcareers.co.uk/search. When I narrow a search using the left hand-side refine rail, an overlay appears where a user has to wait until the search results are returned. The method waits for the overlay to appear and then waits for it to disappear.

public void waitForSRPOverlayToComplete() {

    Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriver())
            .withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.NANOSECONDS)
            .ignoring(NoSuchElementException.class)
            .ignoring(TimeoutException.class);

    **// Error occurs here**
    WebElement blockedOverlay = wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(By.className("blockOverlay"));
        }
    });

    Wait<WebDriver> wait2 = new FluentWait<WebDriver>(getDriver())
            .withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.NANOSECONDS)
            .ignoring(NoSuchElementException.class)
            .ignoring(TimeoutException.class);

    wait2.until(ExpectedConditions.stalenessOf(blockedOverlay));
}

On occasion I get a Timeout exception as the element (blockOverlay) is not found. I have observed the page when this occurs and the overlay does appear but I think sometimes when the search is very fast the above method misses it. I don’t understand why I get a technical error as I have told the fluent wait to ignore them.

This is the code to make the overlay appear:

$('body').block({
            message: $('#loaderEl'),
            css: {
                backgroundColor: 'transparent',
                border: "none",
                color: '#333333',
                fontWeight: 'bolder',
                top: ($(window).height() - $('#loaderEl').height()) / 2 + $(window).scrollTop() + "px"
            },
            overlayCSS: {
                backgroundColor: '#f8f8f8'
            },
            centerY: false
        });

And to remove it

$('body').unblock();

This is the error I receive:

Caused by: org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for     com.efinancialcareers.myefc.desktop.BasePage$6@548238e0
Build info: version: '2.35.0', revision: '8df0c6bedf70ff9f22c647788f9fe9c8d22210e2',     time: '2013-08-17 12:46:41'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_26'
Driver info: driver.version: unknown
    ... 33 more
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"blockOverlay"}

Any help or suggestions would be appreciated.

2 Answers
Related