What will you learn in this lecture?

In the previous video, we learned about the WebdriverWait. In this video, we will study about ExpectedConditions.


Here you can see the expected conditions class living in the appropriate namespace and these expected conditions are basically those explicit waits that we wrote for different kinds of possibilities.

So you can see that we can wait for expected conditions such as alert is present or an element exists or an element is visible or an element selection state to be a certain locator.

We can look for invisibility of element located and then you supply a locator.

We can check for text to be present in an element or we can check for that the title is something specific or that a URL contains some specific fractional URL matches some regex.

So you can see there are many different kinds of expected conditions and that’s why I said that this code right here is not too important because in this case, we were waiting for an element to exist.


We were doing the find element so we’re waiting for an element to exist. However, that expected condition is already present for us and so we can just use the expected conditions class to wait for that condition and save us a couple lines of code and just make our code more readable in that way.

So in this case, for test one being fixed explicitly, we’re waiting for an element to be clickable.


If you remember the slow animation URL, that’s the one where you fill out fill out the forms. We’re waiting for the purchase button, the Go button to be clickable before we click it.

So here it does, that’s what’s gonna happen is the expected conditions and the webdriver wait will pull the Dom for 15 seconds.

For this condition to be true before trying to click if it doesn’t happen, the expected conditions class throws a no such element. I’m sorry. A webdriver time exception.

If that’s not possible and then on the next step we assert that it’s true and then again we use our wait dot until expected conditions that an element is visible by ID success and that it’s displayed and so we’re gonna assert that this element is displayed so we’re gonna wait for it to be visible for fifteen seconds and then assert that it’s displayed whether it’s true.

So rather than talking, let me show you this test executing and so then you’ll be able to see everything going on. So, I’m gonna go ahead and run this test so that you can see it running in real time.

Right, because as you now you know creating a test on a developer environment and then running it in continuous integration are two totally separate things because flakiness comes in in your developer environment, I’m sorry in your continuous integration environment.

So you’ll see that the purchase button was clicked and this test was passed successfully within eight seconds. But however, did you see something weird?

Let me go back to here and let’s debug this test.

Did you see something weird about this?

It seemed to run pretty fast. Right. And even though the loading spinner was still loading, the test somehow still passed.

Let’s take a look at this again.

Now, as we’re gonna put this on the side, there’s the browser coming up. So we’re gonna wait until the go bun and then the go button is gonna get clicked and watch this is still loading but we’re over here this expected condition and then when I step over it. It passes.

Why does it pass well?

Because our success element is visible right at the point when I checked it.

It was the purchase was visible but the whole string purchase complete with the explanation point was not loaded yet, however, this condition was true and the element was displayed so technically it passed but we still didn’t find for the element to be loading.

So let me just finish up running the test so that it kills the browsers.

Next Tutorial

In the next tutorial, we will learn how to customize 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

Share This