I don't understand what's happening with the newer version of Selenium's WebDriverWait but as far as I can see, it's not behaving the way I'd expect it to.
I have tried all the versions from 4.0.0-beta-1 - 4.0.0-beta-4 and I have just updated to 4.0.0-beta-4 as my preferred version.
I use these methods in my own functions:
isPresent
isVisible
isClickable
Each of them have their respective constructors that they call:
WebDriverWait Presence = new WebDriverWait(webDriver, Duration.ofSeconds(1L));
WebDriverWait Visible = new WebDriverWait(webDriver, Duration.ofMillis(1L));
WebDriverWait Clickable = new WebDriverWait(webDriver, Duration.ofMillis(1L));
A couple of things that I found:
- The old constructors would accept their time durations provided as type
Longand in seconds - The new constructors accept their time durations provided as type
Duration Durationhas it's own methods which accept typeLong
Previously, you could write it like this:
WebDriverWait Presence = new WebDriverWait(webDriver, 1L);
Now, it looks like this (as shown above):
WebDriverWait Presence = new WebDriverWait(webDriver, Duration.ofSeconds(1L));
The only difference being how you define the wait.
With using Duration, you can specify the "type":
Duration.ofDays(1L)
Duration.ofHours(1L)
Duration.ofMinutes(1L)
Duration.ofSeconds(1L)
Duration.ofMillis(1L)
Duration.ofNanos(1L)
In my above code example, I define the WebDriverWait using the Duration.ofSeconds(1L), meaning it should wait for just 1 second, however, it waits for 10 seconds instead.
In fact, it waits for 10 seconds whether it's set to Duration.ofMillis or Duration.ofNanos too.
So, either I really don't understand the implementation correctly, or there's something I am missing, or there's an issue with the actual WebDriverWait class.
It's also worth mentioning, it doesn't wait 10 seconds whether the WebElement exists or not, it only waits the full duration if the WebElement does NOT exist.
Hoping someone can assist with this.