What will you learn in this lecture?
In the previous video, we learned how to use pick any tag from HTML body in Selenium of this Selenium webdriver elements identification course. In this video, we’ll have to learn how to use attributes in XPath.
How to Use Attributes in XPath
All right! So, we don’t really need to worry about the periods too much. The dots, I don’t really use them too often. They just help you to work with the nodes. However, what is important is this @ symbol which helps you to select attributes. You guys remember attributes in HTML are things that look like this, right? This body and whatever.
So let’s scroll up here and work with this link. You guys see how this link has an attribute right here which is an ID. And then, it has a value. So actually when I clicked on this link, the XPath that was created for me using fire path inside a Firebug is perfect.
So look what it did! It went through all of the tags. I didn’t even need that dot there. It went through all of the tags regardless of what that tag was. That’s what this star symbol means.
Inside of these brackets, we can specify an attribute which is ID and ask for its value, like that. If you supplied something that doesn’t exist like this and hit enter, it doesn’t select anything. But if you supply something that’s correct with an ID of simple elements link, that works. You guys see that?
If I wanted a different attribute like HREF, you guys can see all of this is inside of the opening tag, right? So if I copy this HREF and use this HREF instead of this ID, okay, and then this I can supply that value and hit enter, it selects the same thing but just using a different property. You guys see that?
If I wanted to work with this clickable icon, we can look at the HTML right here, right? And it is what a tag, which means it’s a link that has a target attribute, an HREF attribute, and some text inside of it.
I will use this HREF and call it icon success copy over that. And so we’ll replace all of this, remove all of that stuff and the attribute is HREF and then the value of that HREF is this. And then we’ll hit enter and it’s selected two things. You guys see that, right? This one and this one which is cool because both of them have an HREF of icon success. And yes, that’s possible!
Our identifier doesn’t care what tag it is. That’s why there’s this wild character here. And then for that tag, it sets these parameters which are HREF of icon success. But, we have two of those. So how can we pick the one we want is we can probably pick the first one, like that. And that still doesn’t help us.
We can probably go to the parent.
And instead of a div, we can do the h4. So here, instead of the star is going to be h4. And then for the h4, inside of that there lives an A. So we need to do a slash A and now hit enter and that selects only our clickable icon text. You guys see that? Because we dug to the parent and inside of the parent there lives a child called A tag and that A tag we want to use it HREF icon success.
Otherwise, if we wanted to get to this guy, we can use a div here. Inside of the div, we have an A that lives. And then the A has some properties as well. See that? And now using this hierarchy, we were able to pinpoint one of these elements.
[Tweet “Learn everything about elements identification with Selenium Webdriver.”]
In the next tutorial, we will cover how to use special operators in 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!.”
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
[Tweet “Learn how to correctly identify elements using #Selenium #Webdriver.”]How
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