In This Course
In this course, you will:
1. Learn the problems that can occur as a result of improper synchronization
2. Learn how to use Selenium Webdriver explicit waits
3. Master Selenium Webdriver implicit wait
4. Understand what a DefaultWait is
5. Comprehend how to use all of the different types of waits during appropriate situations
In this Lecture
This discusses why WebdriverTimeout appears. You’ll also know four examples of explicit waits. Then by knowing these four, you’ll be given a quick test on WebDriverTimeout.
Selenium Tutorial – WebDriver Timeout Exception and Quiz
Guys and Gals, just be sure to play around with the ExpectedConditions class. Find out all of the available options, like I said, you can always just F12 it. Then you can see all of the different possible ExpectedConditions and then you can utilize them for different kinds of situations, whatever you need to happen.
One other thing that I did want to show you is what happens when this query the wait.Until fails. If we F12 there and look at what this does is, let me expand it. You can see that it throws OpenQA.Selenium.WebDriverTimeoutException. This exception is thrown whenever it is unable to locate your element.
For example, if I was to put that to one second and then run this test. I’m putting this to one second, which means that our explicit wait is going to wait for only a single second before timing out. Then the expectation is that the test failed because it couldn’t find it within the right interval.
If we look here, you can see that we have a message and then our OpenQA.Selenium.WebDriverTimeoutException. Then it says, “Unable to locate element.” Then it says which element it was looking for. That’s the exception that’s thrown whenever our wait.Until method fails. I’m going to set this back to ten seconds.
I do have a quiz for you. I wanted to see that if you fully understand everything that we have covered.
Here, we have four examples of Explicit Wait
- We have our thread.sleep example.
- We have a dynamic explicit wait that polls every 500 milliseconds to see when an element comes back.
- We have another explicit wait that uses the longer implementation of the WebDriverWait constructor.
- We have the smaller implementation WebDriverWait constructer that just takes the driver, how long you want to wait before an element time’s out.
With all those four methods and there’s obviously others you can try to make up your own but there’s no need. These are basically all the implementations that you would every use. With all of those four time outs, if I come up here or actually if I got to my test explorer and I select all of these four explicit waits and I run the select the tests, which one of them is going to be the slowest?
Be sure to take a look at all of the methods and see what is going on here. When you come back I’m going to give you the answer.