What will you learn in this lecture?

In the previous video, we learned introduction to HTML tables of this Selenium Webdriver elements identification course. In this video, we’ll have to learn how to get an HTML table in a variable.

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 in on exactly what we want.

So I’m going to take you guys step by step through this process of dealing with the HTML table in Selenium-WebDriver.

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 HTML, table ID.

So you have to do is use that by that ID with HTML table ID. And then store that inside of a table variable.

So let’s do a run up to here. It already had a test running, that’s why it was complaining. So what you guys don’t see is on my other screen, chrome is 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 f10. 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 f10 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 an HTML table. And so you can see the tag name. You can see that 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. Okay! And we got it with an ID 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. I can 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 of the table.

Can anybody think of how we do that to get a collection of all the roles inside of the table? Well, we have our table, right? Mr. single quote, we got our table right. And now we just need to begin 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 use the ID 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 uncomment 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 are right this “find element”. f12 it.  “find element”. You guys see return type iWeb element, right?

And then find elements is going to return us all of the rows into a list, right. If I f12 to find elements, 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.

[Tweet “Learn everything about elements identification with Selenium Webdriver.”]

Next Tutorial

In the next tutorial, we will cover how to use C# to find a cell value.

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!.” 

-Krissy

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

Take This Entire Course for Free

[Tweet “Learn how to correctly identify elements using #Selenium #Webdriver.”]How

0 Shares
Tweet
Share
Share