What will you learn in this lecture?

In the previous video, we learned how to use C# to find all cells in a row 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.

How to Use C# to Find a Value in a Cell

Sweet!

So now that we have all the cells in a row, right? All the cells in a row, a collection of cells in a single row.

What do we need to do? We need to look through them and check to see what is it that they contain. So that we know what we can use, right? And if the text in the cell is equal to our desired column header, which in this case, is a salary. Then, we’re going to store that in the column index, right?

This is going to be index 1, 2 or 3. And we’re storing that in the column index. However, if the cell text contains our desired value, which is a software development engineer in test, we find the salary locator, get the salary, and then write it out using the console.

All right!

So I can see! I talked a lot and you guys probably want me to start running through the code. So we can better understand it. Not a problem!

Let me go ahead! And put a breakpoint right here and start debugging the sucker.

So again, while it’s pulling up the browser, just remember the point, right? We got the table inside of the table. We have the rows. So we grab the collection of rows inside of the rows. We have cells that live.

So we just need to run through every single row and through every single cell and get the values that we want. If the cell has a value of salary, then we want to know whether that column lives. If the row has a value of software development engineering test, then we want to use the column of the salary and the row of this text to get this value.

You guys, hopefully, I hope you get it. Alright!

So for every single row in our collection of rows, right, we have 4. So I’m going to step into this. Now, our collection of rows is 4 but if I use TR, right, it’s 0.

You guys see that? Here TR from 0 to collection of rows count. So when I step into this, what’s going to happen is, now this row only represents the very first row. And it’s going to keep changing right with every iteration.

This row is going to be the one that we’re analyzing. So now that we have this roll, let’s get all of the cells in that row. And each of these rows has 3 cells: 1, 2, 3.

Let’s check it out all cells in a row. And we got one which isn’t right. Let me scroll back up, add a period here. I think that was why I think you did need the period. Step over this again. There you go. Now we got 3. So that was my mistake. You need a period to get all of the cells in a row.

Okay! So now, we have 3, right, because in this row very first one. And actually, let me select that right one so that you guys know what we’re talking about.

Here! There you go!

This is the one we’re talking about, right? Now, we have three cells. Fantastic! Now, we need to go through every single cell and check them for their values.

So for each cell in our collection, let’s step in this cell, right? Now, if we look at this, it is going to be the very first one, right? And that contains the title. But what we care about is that the cell dot text is equal to our desired column header, which in our case, you want salary, right?

So cell dot text. So see that cell right now?  It’s the title because we’re looking at this cell right here is equal to our salary.

And in this case, it’s not. So the column index which is just another variable. This column index will not be stored. It’s negative one, right? Now, so it’s going to throw us problems if you try to use it.

So I’m going to step over this. That’s not going to be the case. And now, also if the cell dot text is equal to our desired value which is software development engineer and test, we need to process it.

But you guys can see that it’s not. So we’re not going to be processing it. So let’s step over this column counter increases. Column counter is just the counter of the column that you are at.

So we started with one because we were in the first column. Now, we’re going to go to the second column. And every time this loop increments, we’re going to increase it. So we increase the column counter.

And now we move on to the next cell!

[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 value in a cell part 2.

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

2 Shares
Tweet2
Share
Share