What is difference between Implicit wait and Explicit wait in Selenium WebDriver? [duplicate]
Asked Answered
D

6

23

There are Implicit and Explicit wait in Selenium WebDriver. What's the difference between them?

Kindly share the knowledge about Selenium WebDriver. Please show the real time example with Implicit & Explicit wait.

Dram answered 26/3, 2014 at 9:29 Comment(4)
It is nothing to add to documentation docs.seleniumhq.org/docs/…Provenance
Kindly refer https://mcmap.net/q/95208/-webdriver-wait-for-element-using-java or docs.seleniumhq.org/docs/…Rideout
The documentation explains clearly what the two kinds of wait do - but it does not explain when to use one or the other, or why implicit waits should ever be required, or why implicit waits are fixed for the life of the webdriver. There's a little bit more info hereFlyman
you can see the documentation of selenium and for real-time example, I would like to refer: asktofolks.com/603/…Groundhog
K
34

Check the below links:

  • Implicit Wait - It instructs the web driver to wait for some time by poll the DOM. Once you declared implicit wait it will be available for the entire life of web driver instance. By default the value will be 0. If you set a longer default, then the behavior will poll the DOM on a periodic basis depending on the browser/driver implementation.

  • Explicit Wait + ExpectedConditions - It is the custom one. It will be used if we want the execution to wait for some time until some condition achieved.

Kildare answered 26/3, 2014 at 10:1 Comment(2)
What does it mean by "poll the DOM"? I am confused by the action of "poll". ThxSequacious
By "poll the DOM" he just means "periodically read the dom again to check for a reload". The poll behavior depends on the specific driver/browser implementation, but its usually like every 0.5 seconds for the implicit wait (if you set implicit wait to ~1s or greater)Disconsider
H
16

Implicit wait --

Implicit waits are basically your way of telling WebDriver the latency that you want to see if specified web element is not present that WebDriver looking for. So in this case, you are telling WebDriver that it should wait 10 seconds in cases of specified element not available on the UI (DOM).

Explicit wait--

Explicit waits are intelligent waits that are confined to a particular web element. Using explicit waits you are basically telling WebDriver at the max it is to wait for X units of time before it gives up.

Hazlitt answered 26/3, 2014 at 12:5 Comment(2)
@JimEvans I totally agree with your point.Hazlitt
@sircapsalot, check this: docs.seleniumhq.org/docs/04_webdriver_advanced.jspHazlitt
N
14

Differences:

1) Implicit wait is set for the entire duration of the webDriver object. Suppose , you want to wait for a certain duration, let's say 5 seconds before each element or a lot of elements on the webpage load. Now, you wouldn't want to write the same code again and again. Hence, implicit wait. However, if you want to wait for only one element, use explicit.

2) You not only need web element to show up but also to be clickable or to satisfy certain other property of web elements. Such kind of flexibility can be provided by explicit wait only. Specially helpful if dynamic data is being loaded on webpage. You can wait for that element to be developed (not just show up on DOM) using explicit wait.

Nikaniki answered 20/11, 2014 at 13:7 Comment(1)
Just one point here from documentation which says: Do not mix implicit and explicit waitsDemasculinize
P
8

Adding another point of view to above mentioned solutions.

Implicit Wait: When created, is alive until the WebDriver object dies. And is like common for all operations.

Whereas,
Explicit wait, can be declared for a particular operation depending upon the webElement behavior. It has the benefit of customizing the polling time and satisfaction of the condition.
For example, we declared implicit Wait of 10 secs but an element takes more than that, say 20 seconds and sometimes may appears on 5 secs, so in this scenario, Explicit wait is declared.

Pawpaw answered 29/8, 2014 at 12:7 Comment(0)
S
3

Implicit waits are used to provide a default waiting time between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the specified amount of time have elapsed after executing the previous test step/command.

Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, Explicit waits are applied for a particular instance only.

Subteen answered 27/5, 2015 at 1:16 Comment(0)
Q
2

My Thought,

Implicit Wait : If wait is set, it will wait for specified amount of time for each findElement/findElements call. It will throw an exception if action is not complete.

Explicit Wait : If wait is set, it will wait and move on to next step when the provided condition becomes true else it will throw an exception after waiting for specified time. Explicit wait is applicable only once wherever specified.

Quaternity answered 22/4, 2015 at 14:31 Comment(2)
ohhh so there's no point in using implicitly_wait more than once? i thought implicitly_wait paused the script for N seconds... lol so implicitly_wait only needs to be set once? and once it is set, then the web driver will wait that many seconds between actions?Orthographize
@Orthographize driver.implicitly_wait(seconds) is global for all elementsChainman

© 2022 - 2024 — McMap. All rights reserved.