What will you learn in this lecture?
In the previous video, we learned how to use C# to find a value in a cell of this Selenium WebDriver elements identification course. In this video, we’ll have to learn how to use C# to find a value in a cell part 2.
How to Use C# to Find a Value in a Cell Part 2
So now we’re in our next cell.
Let’s step through this and you’re going to step over that. This cell with the text work that one is irrelevant to us as well, right? We don’t care about work because the text is not going to equal to what we want here.
So let’s step over this, step over that, step over that.
Column counter increases again. And now we are in column number three. That’s what we should be. Yup! Column number three which makes sense, right? We’re right here.
And so if I step over this, you guys can see that cell dot text is equal to salary. Fantastic!
So if it’s equal to salary, then what do we do? We increase. We store the column index. Column index right now rather than being minus one. It’s going to be the column that we want, which is number three. And you guys see the beauty of this, right?
Because if this salary column moved over to here, number two, or we added another column and we put salary in there, then it would still not matter.
This logic will still work because we would still go through the rows: sell buy, sell buy, sell buy, sell storing the column index. And then based on that, we will dynamically figure out where we need to go.
That’s why this logic is so cool, anyway.
So we step through that cell dot text. It’s not going to equal our desired value because we’re right here. So we’re going to step over this and move through.
This loop is finished, we only had three cells in that row. And now we move on to the next one. We increase the counter. So from 0, we increase it to 1. And now we are at TR is equal to 1 which is here. TR equal to 1 which is this one, right?
So let’s step through that. We’re looking at this guy. And the same thing is going to happen here.
Now we’re going to step through cell by cell by cell. And if the text matches this guy, then we’re going to process it. So let’s go through. Because it will match on this first iteration for every cell in all our cell rows if the cell measured the column header which it won’t because that will only happen one time only for the column headers.
Now we’re checking if it has our desired value which is software development engineer and test which it does.
And so now what we’re trying to get to is this right here, right? So let me actually we’re here. Let’s get to there. So we want the body. We want TR, too. And after TR too, we want table data, right? But which table data do we want? Number three, right?
This guy and this number three corresponds to this column right here: the salary column. That’s why it’s number three. All of these TDs in here are going to be threes: three three three. And so what we do here is we create the school string that’s going to allow us so check it out.
We want this guy, right? So it’s going to allow us to create this dynamic string using the same exact XPath expression. But instead our table row, we are going to replace with the table row count plus one because remember in C# our collection starts at zero.
However, in XPath, our table collection starts at one. This is one. This is two but right now we’re at TR one. So we need to make it two so that it’s equivalent to this value.
And then we need to go one child below into the table data and get. Make it number three which is going to be the column index that we were tracking right here. Whenever we got the salary value, we also got the column index. We started it with its index number three.
And so now we’re using it to dynamically generate this salary locator. And so when I step over it, check it out our salary locator matches the exact expression that we have right here.
You guys see how awesome that is. So we were dynamically able to get this column and this row and based on that, right? This intersection.
So this column and this row get us this intersection. Let me see if I can actually represent that with some XPath.
[Tweet “Learn everything about elements identification with Selenium Webdriver.”]
In the next tutorial, we will cover how to use C# to find a value in a cell part 3.
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