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

Free Video Course

In this Lecture

This lectures talks about a convenient way on how to use the WebDriverWait in ExpectedConditions. The main highlight of this method is you can use this method when using cloud services such as Browserstack and Sauce Labs. It also shows you the advantages of using Polling Interval

Selenium Tutorial – Another Way to Create Instance of WebDriverWait

Let’s take a look here where I’m using the WebDriverWait class again but in a more convenient manner, using the ExpectedConditions class. Also, you can see that I used the second constructor from the WebDriverWait where I pass in my clock to keep track of the time. I pass in again the maximum amount of time that WebDriver is going to wait for an element to appear. Then I passed in the polling interval of every one second. I did this just to show you guys another usage of how to do this.

I personally don’t use this so often. There are not many benefits behind it. One of the main benefits that I’ve seen with this is that it helps you when you’re working with Cloud services like BrowserStack or Sauce Labs because it makes your test output much cleaner.

Let me actually show you what I mean by that. Using this WebDriverWait, what I did was change my set-up rather than doing the basic Initialize and then the RemoteInitialize. That’s why I stuck in that WebDriver Creator class so that it’s really easy for me to change it.

Here, you can see that I logged in to BrowserStack and then I run it in Chrome and Windows 7. If we do that and then I come down here and I run this test, what’s going to happen is that it’s going to run the code in the Cloud in BrowserStack it’s going to poll every second to try and find my element. I’ll show you guys exactly what happens.

Problem

Here I am on Browser Stack. If you take a look, what you can see is it starts looking for the element at five seconds. Find element ID element finish and then it says, “There’s no such element.” It records this screenshot at five seconds, at six, at eight and at nine and then finally it finds it at 11 seconds.

In that mean time, it recorded me all of these four screen shots on me that it can’t find the element which could get a little bit annoying, especially if you’re waiting for an element for 30 seconds. We do have some applications that take like a minute to load. Because they have so much data and or especially if they are not cached and you’re logging into them the first time. Those applications take a minute.

You can imagine I have like 60 screenshots here of it looking for an element, which is a little bit annoying. It could be better if it just said, “It’s looking for an element. ID Finish here for five seconds and then at 11 seconds that element was found.” That will be way more too clear and you don’t have to scroll through so many logs.

Using the Polling Interval

That is one advantage of the polling interval because we can change this polling interval to let’s say something like five seconds.Then when we run this test, we’re going to decrease the amount of screenshots that are produced in BrowserStack. Rather than polling every one second, now it’s going to be polling every five seconds. You see the benefit of that? Now again, like I said, “I don’t use this too often.” It’s up to you guys whether you want to use it or not but yeah, just a preference and let’s go and see what that looks in BrowserStack.

Here I am in Browser Stack again, you can see that we click button to get it started. Then we start looking for our ID finisher element at five seconds just like before but the difference now is we don’t poll again for that until the 11th second.

We just have one screenshot where we try to find it, it wasn’t there. WebDriver said, “Okay, cool. I’m going to wait for five seconds and then I’m going to check for it again.”  Our logs are much cleaner now, correct? As opposed to having many of these screenshots, we just have one and then we haven’t found. It’s displayed as “True” and then we close up and everything is done so that’s the main advantage there.  Like I said, if you want to use it, it’s up to you.

0 Shares
Tweet
Share
Share