What will you learn in this course?
Are you struggling with working with HTML using Selenium WebDriver? Do you know how to easily identify and manipulate an element using Selenium WebDriver? How about performing 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, anytime, on any web application.
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
What will you learn in this lecture?
In this video, we will go through the process on how to get an HTML table in a variable of the Elements Identification course.
Selenium Tutorial – How to Get an HTML Table in a Variable
All right. So as normal we should always start with the very generic the largest parent and then narrow and on exactly what we want. So I’m going to take you guys step by step through this process of dealing with the HVM all table in selenium web driver. So the very first thing to do is to store the table the whole table inside of an element. And luckily our table has an ID right. It is right here table with an ID hemol table ID. So you have to do is use the by DOT ID with HVM on table ID and then store that inside of a table variable. So let’s do a run up to here already how to test running that’s what I was complaining. So what you guys don’t see is on my other screen chromis coming up and within a few seconds the page should load. And now we are here I’m going to step over this.
Usually using up turn but because I have a screen capture software that’s going to stop my screen capture software. So instead I use these buttons on top of town which is pretty annoying to me because you guys know I love shortcuts but it’s what I have to do anyway. So now you can see that inside of this table variable we have a HDMI table and so you can see the tag name. You can see the actually the text which is basically all of the table data and headers separated by newline characters and spaces and that is our table living in a single element.
OK and we got it with an idea which is nice if a table does not have an ID like this one that’s a different story and we’ll deal with that after. So let’s bring this back up here and take it and drag it. I want to drag it over here. And now the next step would be once we have the table we want to get a collection of all the rows inside over the table. Can anybody think of how we do that to get a collection of all the rows inside of the table. Well we have our table right. Missed the single quote we got our table right. And now we just need to dig in to get its rows inside of that. There’s also a table body. Right. What is that going to select me.
Excellent. And inside of the table body we have the table rows. So what if I do this. Boom it selects every single table row. You guys see how that worked. I did not care about the tag. I used the idea of the table to get me down to the right table. Then I went inside of that to get to the body and then I went inside of that to get to the table row. We can probably even eliminate this and you do something like that to get all the table rows but I think it’s a little bit more clear for you guys if I do this same thing. But this is obviously a little bit cleaner. The other one is a little bit easier to understand. So if I uncommon this line over here. Right.
Since we have four rows we have to store them in a list rather than a single variable like we do here in just the iWeb element to see right. This find element of 12:8 find element. You guys see return type iWeb element right and then find elements is going to return us all of the rolls into a list. Right if I F 12 to find aliments it returns a read only collection of iWeb element. You guys see that.
So when we want a collection of objects like we do here to get all of the rows you use find elements and store that in a list just like we did before with the radio buttons because there are multiple radio buttons living inside of a single form. We got that form and then we took all the buttons from it in the table we can do the exact same thing. We get the table and we take whatever contents we want from it and store it in a list of iWeb elements.