3

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:

  1. The old constructors would accept their time durations provided as type Long and in seconds
  2. The new constructors accept their time durations provided as type Duration
  3. Duration has it's own methods which accept type Long

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.

Eitel Dagnin
  • 959
  • 4
  • 24
  • 61
  • 1
    I don't understand what's happening with the newer version of Selenium's - which version you are referring ? – cruisepandey Jul 19 '21 at 15:27
  • @cruisepandey Oh right! Probably a good idea to include that lol.. I have updated my question with the version I am using. :) But for reference here, I am using `4.0.0-beta-3` – Eitel Dagnin Jul 19 '21 at 15:28
  • I hope you do not mix WebDriverWait with implicitlyWait and have no some kind of global WebDriverWait mixed with local WebDriverWait ? – Prophet Jul 19 '21 at 15:29
  • 1
    @Prophet Thank you for the reply. I do not have any other waits that I have explicitly implemented. Up to the point of the `WebDriverWait` implementation, there's nothing else that's been defined/specified. – Eitel Dagnin Jul 19 '21 at 15:31
  • It's says it's beat version, you cannot rely on beta can you ? – cruisepandey Jul 19 '21 at 15:31
  • 2
    @cruisepandey 100% agree. It's definitely a thought that crossed my mind, however there's always the chance I have done/implemented something incorrectly and that could have been what's going wrong. So rather than assume, I'd just ask for help and see if the community is able to advise. :) – Eitel Dagnin Jul 19 '21 at 15:33
  • @EitelDagnin : I acknowledge. – cruisepandey Jul 19 '21 at 16:21

0 Answers0