What will you learn in this lecture?
In the previous video, we have learned about implicit wait. In this video, we will learn the 2nd example of an implicit wait.
2nd Example of an Implicit Wait
So just to prove some of my points, what I’ve done here is I’ve created the same test and it’s called test one fixed implicitly. As you can see, it does exactly what it previously did. However, what it now does is it sets an implicit wait.
You can see here’s the usage that I’ve talked about. And I’ve said that the implicit wait to wait for five seconds. So we’re gonna fill out the credit card info and then we’re gonna find an element and then we’re gonna perform all the same actions as before. But what this means for Selenium webdriver now is any time it uses the find element method it’s going to wait for up to five seconds before it throws an element not visible exception and so it’s gonna wait for 5 seconds and then if it doesn’t work, it’s gonna throw up an exception. Otherwise, it will continue to poll to see if that element is in the Dom before failing.
So let’s go ahead and step through this test.
Actually, let’s just go ahead and run it and see whether this test succeeds. So I’m gonna come here and just click run test and so now the test explorer is good, just gonna go ahead and build. It’s gonna build a couple tests and then it’s gonna start test execution.
We can look at the test explorer and we can see this green bar that keeps moving which means that the test is in execution mode. You can see the browser has opened up here. It’s gonna navigate to our URL, fill out the appropriate information and then it looks exactly like before the test failed again.
When we look at the error, we see the same exact error saying element not visible and then which is very weird.
Right.
Why is the element not visible? I just don’t understand.
Well, it’s exactly as I showed you. It’s the fact that implicit wait is totally useless when the element is hidden on a page. Let me show you. Look. I’m gonna go to this slow animations URL. I’m gonna copy it. I’m gonna open up a brand new browser here and then we’ll take a look at this element that I’m waiting for.
So, for we’re waiting this element called ID success okay and we’re supposed to wait for it for five seconds. So if I got Chrome up and then I look for that element I got Chrome tools up let me hide this over here and then remember we can use the command F feature. Control F if you’re on Windows and we can search by ID so I can actually just search.
Sorry, I forgot the ID that I was looking for success not go success. So if I search for the string success, you can see that there are three elements that I find and we can search through them. So here’s one there’s two and then there’s three okay so here’s the one that we want you can see that this is a div that contains an ID called success and although it is not visible on the page you can see that it’s in the HTML.
In fact, its display is none which means it’s hidden but it’s here in the HTML. But it’s not present on the page so what that means is it’s hidden which means that no matter what.
The implicit wait will never work and what that means is that you can’t resolve this problem using an implicit way that this situation right here you’ll never be able to solve it using an implicit waits.
[Tweet “Learn everything you need to know about Selenium Webdriver implicit and explicit waits.”]
Next Tutorial
In the next tutorial, you will learn how to make implicit waits work.
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
Take This Entire Course for Free
[Tweet “Learn how to correctly use implicit and explicit waits using #Selenium #Webdriver.”]
I get why you shouldn’t use an implicit wait in this example. You don’t know how long it will take for the success message to appear. Using an arbitrary number like 5 seconds doesn’t guarantee the element will be visible in that amount of time.
I have to completely disagree with you that you should NEVER use implicit wait. Your example is not convincing enough. In my experience, implicit wait has definitely helped curb some test flakiness. I use a combination of implicit and explicit waits and it works very well.
Thanks for the input Andy. You can obviously do as you find best. I would just recommend that you take a read of this comment from Jim Evans, the C# Selenium bindings maintainer – https://stackoverflow.com/questions/15164742/combining-implicit-wait-and-explicit-wait-together-results-in-unexpected-wait-ti
“Don’t mix implicit and explicit waits. Part of the problem is that implicit waits are often (but may not always be!) implemented on the “remote” side of the WebDriver system. That means they’re “baked in” to IEDriverServer.exe, chromedriver.exe, the WebDriver Firefox extension that gets installed into the anonymous Firefox profile, and the Java remote WebDriver server (selenium-server-standalone.jar).”…
So, that’s reason why I never use an implicit wait and I recommend my students why not to use it. If you use an Explicit wait and you follow Jim’s recommendation, it means that you can’t use an ImplicitWait, otherwise you will mix. Hence, you shouldn’t ever use an Implicit Wait as per Selenium recommendations.