What will you learn in this lecture?
In the previous video, we learned how to use lists using XPath of this Selenium WebDriver elements identification course. In this video, we’ll have to learn working with tabs and toggles.
Working with Tabs and Toggles
Alright! Ladies and gents, how about we work on some advanced controls, like opening a toggle?
So if you come over here, and you see a toggle here, and you click on it, here’s what we get into HTML. By the way, let me actually show you what it does.
So if I click on it, see that it opens up this text that we can read. So to click on it, you guys see, it has a class. So let’s use that class and see if it gets us the right identifier. Remove all that class equals. Excellent!
So it does work for us. We can use a class to identify this toggle. Now, if there were two toggles that I created, they would probably have this same class. And then, that would not work. And then you would need to use some other identifiers to open and close this toggle.
But in the meantime, it works and then you can use that to read the text that’s in here. Alright? So you can see that text lives inside of the toggle. And then once it’s open, it’s a P tag and inside, there’s some text.
Now, how about tabs? You guys see these tabs over here. So if I click on this one, this is tab 2. If I click on this one, this is tab 1. See how the text changes there and how the tabs actually become black when they’re selected.
So how can you click on the appropriate tab? Well, let’s take a look! So if you use our Firebug to highlight here, you can, first of all, see that it has a link, and it has text and size called tab 2. And it has an HREF which is just a hashtag and it’s also a class of ETPT tab active.
How about this other one that’s not active? It has a like class of blank and then it’s HREF is this. So if we want to click on tab 1, we can do something like an A. And then it contains text open closed brackets, text, comma and the string. And we’ll put that in here, tab 1.
Make sure you close this bracket here, square bracket, hit enter, and it’s selected. If we want to select container 2 or tab 2 just hit tab 2, that’s selected. And we can probably even take it a step further and not require the A and just give it a star. And that actually makes it even better and more stable because we’re not dependent on having the A tag there.
It can be any tag in as long as it contains tab 2 we’re happy or tab 1 that will also work. And you can even decide if a certain tab is active by doing something like an ally. So do that and then inside of that we have our A living, right?
So if we hit enter here, that did not work. Now, why is that, guys? Why can anyone decide to figure out why it doesn’t work? Well, it’s actually pretty simple. It’s because tab 1 which we have here is not active. It’s tab 2 that is active.
See that how it works? Because tab 2 has this class which is active. Tab 1 is not, so it does not work. So using Selenium WebDriver, we can just check to see for example, if this web element is returned. If not, then we know that it’s not active. And that’s how we can decide which types to click or even better we can just click on the appropriate tab, whether it’s active or not.
And so that’s how you work with tabs. And then if whenever you open one up, you can go inside and just read the text.
In the next tutorial, we will cover the introduction to HTML tables.
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