What will you learn in this lecture?

In the previous video, we learned about explicit waits. In this video, we will learn 2 types of explicit waits.

2 Types of Explicit Waits

So, an explicit wait is a code that you write to wait for some specific condition to happen before proceeding.

One of the simplest ways to do in the next input explicit wait is to use a thread sleep thread and then you, of course, need to import system dot threading and then you can do thread dot sleep and then you can set a time span in mill.

If you want to do milliseconds let’s say we want to do 1000 milliseconds which is obviously one second this right here is an explicit wait because you’re writing code that will tell the system to wait for specific condition.

In this case, to wait for one second.

This is the worst kind of an explicit wait and it should actually never be used.

Well, that’s not true.

It should only be used in situations whenever you actually need to wait so.

For example, if you click a button and then some action is supposed to happen 30 seconds or 40 seconds after your button click, then you can use a thread that sleep.

However, it should never be used to wait for an element to actually load the other type of an explicit wait you can have is again another example of writing code is like this.

For example, here we’re going navigating to this hidden element URL. Then we’re using a webdriver weait class that comes from Selenium namespace.

Don’t worry about this right now. We’ll cover this more in detail and using the webdriver wait class.

We write a link query that will wait until we find an element of this ID. So, this will continuously poll the Dom to see if this condition becomes true.

Let me show you exactly what I mean.

Here so, I’m gonna go ahead and debug this and show you exactly what’s happening.

This is another example of an explicit way because it’s code that we wrote to wait for a specific condition. In this case whether the element is found, we could wait to see whether the element is displayed.

We could wait to see whether the element is visible, whether there is text in an element or something like that.

So, here we have the two elements, the two pages side by side and you know that on this page, it’s the hidden element URL which means the element is there but it’s hidden. And so now what we’re gonna do here is step over this action and you can see it’ll throw an exception.

No such element, but then it comes back and does it again.

Every half a second, it will continue to poll to see if the element is there and after our specify the timeout that we set which was 20 seconds if it has not found that element, it will throw a webdriver timeout exception saying that timed out after 20 seconds because the element is not there.

So that code that I wrote telling Selenium-webdriver to wait for a specific condition on a specific element now this way is good but a little bit burdensome.

Luckily for us Selenium has created a very convenient way to perform this kind of operations and that’s called expected conditions and I’m gonna show you that to you next.

Next Tutorial

In the next tutorial, we will talk about the WebDriverWait.

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

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

Pin It on Pinterest

Shares
Share This