What will you learn in this lecture?

In the previous video, we learned DOM in Selenium WebDriver of this Selenium Webdriver elements identification course. In this video, we’ll have to learn how to evaluate elements at runtime.

How to Evaluate Elements at Runtime

In this video, I quickly wanted to cover an amazing technique that’s going to drastically reduce the amount of time that you spend doing debugging in your automated functional tests.

So what I’m going to do here is pull up our Chrome browser utilizing Selenium Webdriver. So I’m going to come here in my test explorer. And actually, I’m just going to execute from here and I’m going to do debug. It’s going to go ahead and open this URL where we’re doing all our automation practicing.

So the problem that I’ve seen too many times with people is, and it’s actually very frustrating, is a lot of people actually don’t know how to debug in an efficient manner. So what happens is usually we have this kind of test where we, you know, navigate to a URL.

Then we click some other maybe URLs. Then we do some stuff. We fill up, do some actions, you know to fill out some forms, proceed to next pages, and do that. For you know, however long it takes for an automation test to happen, the problem is what happens whenever you begin to run into errors.

For example, a lot of times you’re going to have issues, like dealing with elements. You may identify an element in the browser correctly, but when you go to place that into your code, it doesn’t work for whatever reason.

A lot of times you will notice with XPath. For example, there are some certain conventions so when you stick in a string of XPath into Selenium WebDriver, it won’t let you do it.

I don’t know if I have any examples here, but if you have any kinds of locators that look like this. For example, let me see here. So it’s some kind of a locator like this where there are spaces in XPath.

And the code will actually complain and say that you can’t have such an ID with a bunch of spaces. So you’re actually going to need to break it up into XPath. So stuff like that you know the browser will recognize it because it’s valid in the browser. But when you go to utilize it with Selenium but WebDriver it’s not valid.

You’ve got to run into errors. So the problem that I see is that many people, what they do is when the code breaks, they look at the error. They put a breakpoint like I did, and then they’ll rerun the entire test and that can obviously be very time-consuming.

So for example, if it takes 45 seconds to get to the location where you want to get to. Now, every time you need to deal with this error, you’re going to spend 45 seconds. And a lot of times, I caught myself in the past doing this over and over especially with element locators because I would be, sometimes, the locator that I find just would not be stable enough.

And so I would need to keep doing this and it was a huge waste of time. So what I want to show you is what’s called this immediate window right here. The immediate window you can actually get from visual studio by going to debug windows immediate right there.

Okay so once you get it out. What does this do? It actually allows you to execute commands on the fly while your code is paused. It’s really fantastic!

So for example, let’s try to click on this link. So here’s the link. I’m going to actually click it using its HREF. You see actually how the IDE is actually alive here. It helps you out. So here I have an element that I’m attempting to locate and I can execute the statement here.

And if it fails, it will just fail here. And it won’t affect my test. Let me show you! So check it out. Look! It actually threw an exception saying that no such element exists. But if I was doing this in the test and I attempted to have this line of code over here in my test, what would happen is my test would crash and then I would need to start everything all over.

But instead, I can play around with the locators here until I get it right. So if I wanted to get it right I could obviously update this to be the correct attribute. And so now you can see that I actually got back an element.

If you wanted to take this a step further, you can actually store it in a variable. Okay! There we go! And now with L, I can access this element. Let’s see if it actually clicked. Did you see? It actually clicked the element to take me to this filling out forms page. Did you see that?

So it actually works. You can actually execute a command and it’s basically a trial around here in the immediate window until you get everything right.

And then when you, you know, get your locators down interactions with the web elements down, you just plop it in your code and proceed. You can basically!

It’s pausing the application, and your code in a single place, and allowing you to play with the code until you’re satisfied.

So please use this, because I’ve caught myself so many times running through code over and over just to get to a specific location, and then debug that location, and it will fail, and I’ll do it again, and then it’s a fail.

Now, to do it again, and it sucks, and it’s a waste of time.

So hopefully, you liked this tip. Talk to you later!

[Tweet “Learn everything about elements identification with Selenium Webdriver.”]

Next Tutorial

In the next tutorial, we will cover bonus offer for current students.

What will you learn in this course?

Are you struggling with working with HTML using Selenium WebDriver? Do you know how to easily identify an element using Selenium WebDrriver? Do you know how to manipulate that web element? Do you know how to perform a drag n’ drop on an element? If not, then these are just a few of the questions that will be answered in this course.

This course is a complete guide on working with web elements in Selenium WebDriver! Once you are finished with this course, you will know how to work with any web elements, any time, on any web application.

“Relevant content that I will be able to apply to my automation tests *immediately*, a VERY effective presentation approach (evolving the same example and comparing/contrasting), and an excellent teacher / presenter. Thank you so much for your time and sharing your knowledge Nikolay!.” 

-Krissy

In this course from Ultimate QA, you will learn:

  • Basics of HTML
  • All the different locator strategies for Selenium WebDriver
  • How to identify web elements using Selenium WebDriver
  • Master XPath
  • Navigation with Selenium WebDriver
  • Web element manipulation
  • Web element interrogation
  • Mouse and keyboard actions with Selenium WebDriver
  • Performing actions such as drag n’ drop, drawing, hovering
  • Implicit and Explicit waits
  • How to properly handle element identification so that your tests are not flaky
  • Expected Conditions in Selenium WebDriver

Take This Entire Course for Free

[Tweet “Learn how to correctly identify elements using #Selenium #Webdriver.”]How