What will you learn in this lecture?
In the previous video, we learned how to use special operators in XPath of this Selenium web driver elements identification course. In this video, we’ll have to learn how to identify a button using XPath.
How to Identify a Button Using XPath
So over the next few lectures, I want to take a lot of time to get you guys really familiar with XPath. I want to take you through all different scenarios from simple to really complicated so that you can understand how to identify any element at any time for any condition.
And after we go through a bunch of those exercises, then we can jump into Visual Studio and try out a few other things because the easiest thing after learning XPath is actually using it in Visual Studio. Because once you know how to identify elements the rest is pretty much irrelevant.
That’s the same thing as we have been doing before. So let’s start with a button element. And I would like to go through a few strategies on locating it.
So if we go up and try to look at this button, ok come up here. So this is the initial XPath that is given to me, right? It’s long, dirty and hard to understand. If we wanted to fix this up, we can look at this element down here and see what does it have.
Well, it has a class name, right? So let’s try using a class name, so you can obviously just use that in Selenium web driver, and use finds by class name or you can come here or remove all of these. Remember classes the attributes and then just supply its value. Hit enter and it almost works, right?
You guys see how it almost worked because now it’s highlighting two buttons because both of these buttons have a class name which leads me back to the class example. When I told you guys sometimes it may be unique, other times it may be not.
So that’s when we need to decide on how to identify the element. So as you can see the class name is not sufficient enough to pick up the right element. So what we have to do is probably use the text of the class name that tells us to pick this as opposed to this, right?
The text in here is “go to log in page” and the text in here is “click me”. You guys see that? So let’s put those identifiers in here. Put this on the side with that here.
Oh by the way guys, this is also a link, as you can see. So you can just use Selenium as a link text in order to click it, right? So you can use this link as you go to “click me” or you can use one of my favorite techniques which is using contains text to click on the button that you need.
So if I do this, and then hit enter it selects only those button. Just go down. You guys see that it doesn’t like this button anymore. So like only this button and this is actually one of my favorite techniques to identifying some elements and you guys should get really familiar with it.
In the next tutorial, we will cover how to figure out if an element contains some text.
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