Fluent Wait Modification

In this section, we will discuss about the Fluent wait modification introduced in Selenium 4 version. Fluent wait is one of the important wait concept of Explicit wait in selenium.

Fluent wait in selenium is one type of explicit wait in which selenium script will wait for maximum wait time until the expected condition satisfied and verifying the condition frequently before throwing an exception like ElementNotVisibleException.

Fluent Wait Modification

In simple language, Fluent wait is checking the Web Element in regular interval before throwing the expected condition.

Here the time script will check the WebElement frequently in regular time is known as Frequency.  Frequency is also known as polling period.

Let’s say because of the Ajax and page loading issue, one WebElement is taking 10 sec time to load properly and sometimes it is taking 20 also. WebElement loading is not fixed and varying time to time. So if we declare the explicit wait with maximum time 10 then sometimes  ElementNotVisibleExceptionwill be thrown because WebElement is not loaded fully.

Modifications in Selenium 4:

Some method changed in fluent wait in selenium 4. The method such as withTimeOut() and pollingEvery() has been replaced by TimeUnit with duration.

Let’s understand the modifications with simple syntax.

Selenium 3:

Fluentwait wait = new FluentWait(driver).pollingEvery(20, TimeUnit.MILLISECOND).withTimeOut(20, TimeUnit.SECOND).ignoring(NoSUchElementException.class)
  • FluentWait(): This will accept the webdriver reference in which we need to implement fluent wait.
  • withTImeout(): This will accept the maximum time driver will wait before throwing an Exception.
  • pollingEvery(): this will accept the regular time driver will check the visibility of the WebElement. For example, if we have given withTimeout as 30 sec and pollingEvery as 5 sec, then in every 5 sec driver will check the visibility of the web driver reference we have mentioned in FluentWait() till 30 sec. if it does not find the element till 30 sec, it will throw an Exception and proceed with the next test case.
  • ignoring(): This will accept the exception class. We need to mention that Exception class which you want to ignore till the maximum time mentioned in withTimeout and at every pollingEvery() time when it checks the visibility of an Element.

Selenium 4:

Fluentwait wait = new FluentWait(driver).pollingEvery( Duration.ofMilis(200)).withTimeOut(Duration.ofSeconds(200)).ignoring(NoSUchElementException.class)
Fluent Wait Modification

Summary:

  • Fluent wait in selenium is one type of explicit wait in which selenium script will wait for maximum wait time until the expected condition satisfied and verifying the condition frequently before throwing an exception like ElementNotVisibleException.
  • pollingEvery() will accept the regular time driver will check the visibility of the WebElement.
  • ignoring() will accept the exception class. We need to mention that Exception class which you want to ignore till the maximum time mentioned in withTimeout and at every pollingEvery() time when it checks the visibility of an Element.

In this section we have discussed about the Fluent wait modification in Selenium 4. In next section we will discuss some more features of Selenium 4.

Leave a Reply

Your email address will not be published. Required fields are marked *