What will you learn in this lecture?
In the previous video, we learned how to identify a button using XPath of this Selenium web driver elements identification course. In this video, we’ll have to learn how to figure out if an element contains some text.
How to Figure Out if an Element Contains Some Text
And this statement right here let’s break it down.
So we have our double forward slash which obviously selects any tag in the body and we drill down to the A tag. And for the A tag, we want to use two XPath functions.
This guy and this guy actually XPath functions that tell us what we want. So we want to use the XPath function that says “contains”. And what does it contain? It contains text that says “click me”. The text that says “click me”. You guys see that?
And this is one of my favorite tools for identifying all the different types of buttons because a lot of times elements won’t get those unique identifiers as you guys see here. And so you can actually identify it by text. Yes, it sucks when the text changes but you just have to update the text.
And a lot of times, the tags do not change. If you want to, for example, click the “email me” button. You just change the text to “email me”, like this. And then, if I hit enter, that did not work. Why didn’t it work?
Let’s see! Because first of all, the “email me” is not inside of the A. You guys see that? It’s not inside of the A. It’s inside of the span. So if we come here and paste this, and then instead of the A, we make it a span, right? That’s the…That’s this guy right here span.
See that? And then and here we put the text email. It doesn’t even have to be the full thing. And I hit enter. Boom! Now, I got what I want to click on. You guys see that? Just by changing the text. And it’s really nice because you can pass in any string.
And as long as it contains that string you can click on that element.
So now, you guys saw three different strategies to identifying this button. We saw this one where we can use the link text which is equal to “click me”. We can use this guy and we can use this guy.
So probably overall the best strategy to do here is to use link text because it’s the most simple one. But again that’s always up to you to decide it. But when you look at all of this written out versus this to me much simpler to just use by the link text and then you just pass in the link text, right?
[Tweet “Learn everything about elements identification with Selenium Webdriver.”]
In the next tutorial, we will cover how to identify link and icon 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!.”
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