What will you learn in this lecture?

In the previous video, we learned how to use attributes in XPath of this Selenium web driver elements identification course. In this video, we’ll have to learn how to use special operators in XPath.

How to Use Special Operators in XPath

So here, I have a few examples of everything we talked about. And what I quickly wanted to show are these last two right with these two slashes. It doesn’t matter what the tag is but we can skip everything and select the tags that we want.

So if I scroll down here to this table, we can see a cell. If we look at a cell here, it has a TD. Inside a TD lives some texts. Here check out another TD where some texts lives and another TD, table data.  And the table data lives inside of a TR, which is a table row.

So if I wanted to select all of the table rows, anyone knows how I would do that? Well, so first I would put these double slashes right because we don’t care. We want to skip all of the parent structures and just get right down to the element that we want. And that would just be by putting TR here.

And if I hit enter, check it out! It selects every single table row. That’s what TR stands for a table row if I wanted the table body. I can do. I can do that! And now, it selects every single table data on this page.

You guys can see it selected every single TD tag if I wanted a specific one that’s a little different question. But for now, this is how you use these double forward slashes.

And now, if I wanted all of the attributes like class, I can do something like this. So now, it’s going to select every single class attribute on this page. If I hit enter, it selected them. If I wanted every single ID, check it out! See how it is selecting every single ID.

If I wanted every single  ID, how about HREF, which is our link A trap, you guys see that! It is selecting every single link. So using this double slash in the @ symbol, and whatever attribute you want, you can select exactly, you can select all of the attributes.

And then obviously, we already went over this wildcard character just like anywhere else. It matches any element node. And then this matches any attribute node. So take a look at that! So any element node, that’s how I was doing this, right?

So if I hit enter now, what is it going to do? It’s going to select everything on the page. You guys see that? But then, if I wanted to do that and then just skip to a certain attribute, maybe I can do something like type. That’s not going to work to do like that. Type all the types.

And then if I do like this, it’s going to select every single attribute on the page. You guys see that? Select every single attribute on the page.

So you can use the star to skip through the HTML to get to the point where you want. Is that awesome wildcard character that we use everywhere else in all, even encoding?

And then finally, I also want to talk about the pipe which can allow us to select multiple elements. So for example, if you go back to this table, and I look at this table, I can select all of the TDs, right? Check it out all the table data.

And I can select all of the TRs table rows and table data or I can select all of the TDs and just the table headers. You guys see that? Instead of the table data, how about I just select the table rows, table rows and table headers. You guys see that? How it’s not only selected here. All the THs and all of the TRs are selected.

You guys see now how cool is that. So that’s what the pipe does.

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

Next Tutorial

In the next tutorial, we will cover how to identify a button using XPath.

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