What will you learn in this lecture?
In the previous video, we learned how to use C# to find a cell value of this Selenium WebDriver elements identification course. In this video, we’ll have to learn how to use C# to find all cells in a row.
How to Use C# to Find All Cells in a Row
Oh! By the way guys, this is probably an amazing interview question where they check to see how you use logic to figure out a problem like that, right?
So make sure you learn and understand everything that’s going on here. So what we need to do is circle every single row in our collection of rows, right? So for every single row, we need to read every single cell and get its value. You guys see that read it cell and get its value.
Once we figure out that we have a software development engineer in test value, we need to note that row. And once we know this row and we know the header here, we can use the headers index which is this number three and the row’s index to figure out where this value lives.
And as we step through the code, hopefully, it would make more sense to you guys. Let me, this is all actually good, so let’s take a look here at the code first. And then we’ll step through it.
So for every TR, right, a row in our collection of rows that count, we’re going to do a normal loop. We’re going to increment and we’re going to start TR at zero. And the very first thing we need to do is set the row equal to the collection of rows and then the index.
So if we start at zero, this row variable is going to become our first row. In this case, it would be zero which would be the header row. Then as we circle to the next one, this guy would become this role. Just so we know which row we’re working on. And we have that stored inside of a variable.
Okay! So when we get that single row, that we’re going to work with for this loop iteration, we need to get all of the cells in that row. And to do that, so let’s actually do that, right?
Now, so if we’re looking at a row. So if we get this first row, right? We are in the first iteration of the loop. You guys see I put TR 1 here. Now we’re working with this row.
How do we get all of its title headers? Well, that’s simple! So you do the dot. And so now we found all of the table headers but remember that the table headers only live in the first row.
In the second row, we got table data that lives. So we need something better than this locator. Well, what if we just did a star here, would that work? Of course, it would! It would select all of the. It would select our first row and then after that. Whatever lives inside of that, it doesn’t matter.
It can be a star. Take a look at the second row. Boom! You guys see? That selects every single cell inside of that.
So over here, this is what our XPath query does. In fact, we don’t even need this dot here. And so this will get us all of the cells, right? So now, we have the row and inside of the row, we have every single cell.
In the next tutorial, we will cover how to use C# to find a value in a cell.
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