0

I understand that this question has all possible duplicates. But the thing is, i wanted to know the difference with respect to current version of selenium.

My point of view is, both the wait has options to Poll the time and ignore the exceptions, then whats the advantage of using this fluent wait

Kaushik
  • 89
  • 1
  • 12
  • Does this answer your question? [Implicit vs Explicit vs Fluent Wait](https://stackoverflow.com/questions/48145111/implicit-vs-explicit-vs-fluent-wait) – Naveen Mar 18 '20 at 17:37
  • Nope it does not because both explicit and fluent has polling timeouts and ignore methods available. Apart from customized conditions what's the exact difference – Kaushik Mar 19 '20 at 04:40

1 Answers1

3

They aren't different types of waiting, WebDriverWait is a specialized version of FluentWait with some different constructor options.

In the WebDriver java library, there are 3 types in the inheritance tree of WebDriverWait:

Wait is a generic interface for waiting until a condition is true or not null. Very basic and doesn't define how any of this is done.

FluentWait is an implementation of the Wait interface that may have its timeout and polling interval configured on the fly. This class is generic and requires a type <T>

WebDriverWait extends FluentWait and is a specialization that uses WebDriver instances.

Prefer WebDriverWait over FluentWait when your generic type <T> would be <WebDriver>. It aims to ease construction.

Given this instance of WebDriverWait

    WebDriverWait wait = new WebDriverWait(driver, 30);

This is what an equivalent FluentWait looks like to create

    FluentWait<WebDriver> wait = new FluentWait<>(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER);
    wait.withTimeout(Duration.ofSeconds(30));
    wait.pollingEvery(Duration.ofMillis(500));
    wait.ignoring(NotFoundException.class);

This is as far as the difference goes. The resulting object will behave the same. WebDriverWait just gives you those defaults for free.

Julian
  • 1,665
  • 2
  • 15
  • 33
  • I agree to your point, after looking into the documentation i could see more or less both has the same mechanism and share same methods. But i am still ore curious on whats the exact difference between the waits. If both does the same then why fluent wait has a subclass webdriverwait. Any practical difference would be appreciate – Kaushik Mar 19 '20 at 16:42