0 votes
in Selenium by
What are the different types of waits that WebDriver supports?

1 Answer

0 votes
by

1. Implicit Wait: Implicit wait instructs Selenium to wait a specified amount of time before throwing a "No such element" exception (One of the WebDriver Exceptions is NoSuchElementException, which occurs when the locators indicated in the Selenium Program code is unable to locate the web element on the web page).

Before throwing an exception, the Selenium WebDriver is told to wait for a particular amount of time. WebDriver will wait for the element after this time has been set before throwing an exception. Implicit Wait is activated and remains active for the duration of the browser's open state. Its default setting is 0, and the following protocol must be used to define the specific wait duration. 

Its Syntax is as follows: 

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

2. Explicit Wait:  Explicit wait tells the WebDriver to wait for specific conditions before throwing an "ElementNotVisibleException" exception. The Explicit Wait command tells the WebDriver to wait until a certain condition occurs before continuing to execute the code. Setting Explicit Wait is crucial in circumstances when certain items take longer to load than others.

If an implicit wait command is specified, the browser will wait the same amount of time before loading each web element. This adds to the time it takes to run the test script. Explicit waiting is smarter, but it can only be used for specific parts. It is, nonetheless preferable to implicit wait since it allows the programme to stop for dynamically loaded Ajax items. 

Its Syntax is as follows: 

WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);

3. Fluent Wait: It is used to inform the WebDriver how long to wait for a condition and how often we want to check it before throwing an "ElementNotVisibleException" exception. In Selenium, Fluent Wait refers to the maximum amount of time that a Selenium WebDriver will wait for a condition (web element) to become visible.

It also specifies how often WebDriver will check for the presence of the condition before throwing the "ElementNotVisibleException." To put it another way, Fluent Wait searches for a web element at regular intervals until it timeouts or the object is found. When engaging with site items that take longer to load, Fluent Wait instructions come in handy. This is a common occurrence with Ajax apps. It is possible to establish a default polling period while using Fluent Wait. During the polling time, the user can configure the wait to ignore any exceptions. Because they don't wait out the complete duration defined in the code, fluent waits are also known as Smart Waits. 

Its Syntax is as follows: 

Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

Related questions

0 votes
asked Mar 29, 2021 in Selenium by sharadyadav1986
0 votes
asked Jan 30, 2020 in Selenium by Deepanshu Burreja
...