0

Disclaimer: I am relatively new to selenium and Java.

I have gone through the selenium source code and found that WebDriverWait extends FluentWait<WebDriver> and FluentWait<T> implements Wait<T>

Doesn't that make WebDriverWait the Superset which has all the methods of FluentWait and Wait class? So my quesiton is:

What is wrong(in my understanding) or what is the difference in the below code.

WebDriverWait:(below)

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.ignoring(NoSuchElementException.class);
wait.ignoring(StaleElementReferenceException.class);
wait.ignoring(ElementClickInterceptedException.class);

FluentWait:(below)

FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)
                .withTimeout(30, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class)
                .ignoring(StaleElementReferenceException.class)
                .ignoring(ElementClickInterceptedException.class);

What I am try to have is a wait object which ignores these three exceptions.

NoSuchElementException
StaleElementReferenceException
ElementClickInterceptedException

Any help is appreciated. Thanks in advance.

1

FluentWait: According to your code snippet, it will wait for the expected web element upto 30 seconds. And it will check the condition (or in simple words, look for the element) every 5 seconds within the 30 seconds time limit.

You can use FluentWait when your web element appears or loads between some time interval.

WebDriverWait: The WebDeiverWait code snippet will also wait for the element for 30 seconds. But it will look for the element every 0.5 seconds (500 ms) by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.