Implicit and Explicit Wait in Selenium Thread.sleep Fluent Wait:

 

  1. Implicit Wait

  2. Explicit Wait

    • sleep

    • WebDriverWait

    • PageLoadTimeout Command

    • SetScriptTimeout Command

  3. FluentWait

 

1. Implicit Wait:

  • Implicit Wait means informing selenium web driver to wait for specific amount of time.
  • If the web element is not visible after waiting for that specific point then throw “NoSuchElementException”.

 

Syntax Of Implicit Wait:

 

Example of Implicitlywait:

2. Explicit Wait:

  • In Explicit wait along with wait time we also provide the wait condition for particular WebElement.
  • It will wait till the condition or the maximum wait time provided before throwing the Exception “ElementNotVisibleException”.

 

  1. Thread.sleep

  2. WebDriverWait

  3. PageLoadTimeout Command

  4. SetScriptTimeout Command

 

1. Thread.sleep Command

  • The sleep code always has to wait for the seconds mentioned within the bracket, even if the work page is ready after 5 seconds. So this test can slow down.

 

Example:

 

Example of Thread.Sleep:

2. WebDriverWait

  • Before proceeding any operation, wait for a certain position before proceeding with the code.
  • Wait for the WebDriver to check whether the element exists or to operate on it, visible or enabled or disabled or clickable.

 

ExpectedConditions class can be useful in a lot of cases and provides some set of predefined condition to wait for the element. Here are some of them below:

 

findElement using locator and store into WebElement element to use in ExpectedConditions class:

 

alertIsPresent :

 

elementToBeClickable:

 

elementToBeSelected:

 

frameToBeAvailableAndSwitchToIt:

 

invisibilityOf:

 

presenceOfAllElementsLocatedBy:

 

textToBePresentInElement:

 

textToBePresentInElementValue:

 

visibilityOf:

 

titleContains:

 

Example of WebDriverWait:

 

3. PageLoadTimeout Command

  • Determines the amount of time to wait for the page load to complete before the error is thrown at the end of time.
  • If the timeout is negative, then the page load may be indefinite until the pageload.

 

Example:

 

Example of PageLoadTimeout:

 

4. SetScriptTimeout Command

  • Before throwing an error, the amount of time is set to wait for the asynchronous script to complete the execution.
  • If timeout is negative, then the script will be allowed to run indefinitely.

 

Example:

 

Example of SetScriptTimeout:

3. FluentWait Command

 

  • Fluent Wait uses two parameters to handle wait– timeout value and polling frequency.
  • Fluent wait is another type of Explicit wait and you can define polling and ignore the exception to continue with script execution in case element is not found in webpage.

 

First of all, it sets the following values.

  1. Maximum time to wait for any condition.
  1. Frequency to check the success or failure of a specified position.

 

Example of FluentWait using WebDriver wait:

Implicit, Explicit, & Fluent Wait in Selenium WebDriver and WebDriver Wait, Implicit Wait, Explicit Wait, Fluent Wait and Implicit and Explicit Wait in Selenium and Implicit and Explicit Wait in Selenium and Implicit and Explicit Wait in Selenium