What will you learn in this lecture?
In the previous video, we have learned the answer to why the test is flaky. In this video, we will learn about implicit waits in Selenium webdriver.
What is an Implicit Wait
So Selenium provides us several ways to deal with synchronization problems. One of those ways as you may have heard in the industry you may not it’s called an implicit wait. Well, it’s actually called an implicit wait. About implicit wait means you no more different options.
So what is an implicit wait?
Well, an implicit wait basically tells Selenium webdriver to pull the document object model for a certain amount of time when trying to find an element or elements if they are not immediately available. So it’s basically checking the DOM to see if that element is present. If it’s not present, it’s gonna keep checking for a specific duration of time.
So how do you use an implicit wait?
Well, an implicit wait that’s pretty easy to use. You do driver dot manage that timeouts that implicit wait. It’s a property and then you set it to some timespan object and then you set from seconds, from minute, from days, and so on and so forth.
I hope you’re not setting implicit waits for days but it should you normally it’s from seconds or from milliseconds depending on your implementation. And of course, I’ll show you that in code what is the default timeout so if you do not set your implicit wait right as you can see in the usage, I’ve set it. But if you don’t set it, the default timeout is actually zero seconds.
So what that tells webdriver is if you’re looking for an
element using driver that find element and it doesn’t find that element, it’s gonna fail immediately which is exactly what you saw in our initial test where it was looking for that final element to check and that element wasn’t present in the DOM. And so the tests failed.
What are the disadvantages of an implicit wait?
The disadvantages of an implicit wait are that it’s useless if the element is hidden on a page. So what does that mean? It means that if the element is there but simply just hidden, the implicit wait will not work. In fact, it will fail immediately.
I’ll show you that after the other problem with implicit waits although it’s less of a problem than the first one, the first one is a huge major problem that’s going to cause insane flakiness in your tests. But the second one it’s still also a problem but it’s that the implicit wait applies to all future commands utilized in your test.
So if you set implicit wait once it will now apply from this point forward to all of your tests that are running obviously executing within that driver right while the driver is existing in memory, it will all be applied to that all those future commands. so whether you want your driver to wait for a long time or you don’t, it’s always gonna wait for that set amount of time.
So, when should you actually use an implicit wait?
The answer is actually never. Yes. I know you must be annoyed right now because I’ve just spent all this time teaching you about an implicit wait and then I’m telling you never to use it how can that be?
Why did I do that?
Well, the reason I did that is so you know about implicit waits. You know what they are and then you know that you should never use them. In fact, there is no reason that I’ve ever encountered why you would need an implicit wait. In fact, after everything I show you, you’re gonna realize that implicit waits is not only useless but because you can’t combine it with an explicit wait and you shouldn’t have recommended by Selenium web driver. You shouldn’t mix implicit and other waits then it becomes the fact that you should never use implicit waits let me convey to you that through course code and examples
[Tweet “Learn everything you need to know about Selenium Webdriver implicit and explicit waits.”]
In the next tutorial, you will learn the 2nd example of an implicit wait.
What will you learn in this course?
Are your automated functional tests flaky? Do they randomly fail and you are unsure why? Is your team frustrated with the “instability” of your Selenium Webdriver tests?
If you are interested in fixing all of these problems and making your tests more stable, then you need to understand how to use all of the different types of waits in Selenium Webdriver. Knowing how to handle synchronization issues will make you a top-notch Test Engineer!
“The best tutorials I have ever seen, simply awesome. I take off my hat in front of you, you are a gorgeous professor, I am speechless to express how satisfied I am with these tutorials.” -Lisbey
In this course from Ultimate QA, you will learn:
– Learn the problems that can occur as a result of improper synchronization.
– Learn how to use Selenium Webdriver explicit waits.
– Master Selenium Webdriver implicit waits
– Understand what a DefaultWait is
– Comprehend how to use all of the different types of waits during appropriate situations
[Tweet “Learn how to correctly use implicit and explicit waits using #Selenium #Webdriver.”]
Nikolay Advolodkin is a self-driven SDET on a lifelong mission to create profound change in the IT world and ultimately leave a legacy for his loved ones, community, and the world at large. Today, he serves as the CEO and Test Automation Instructor at UltimateQA.com and contributes informative articles to leading test automaton websites like SimpleProgrammer.com and TechBeacon.com