Going Through Each Cell in a Dynamically Generated Grid

PROBLEM

You need to go through each cell contained in a ASP .NET Grid control like the one seen here:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx

SOLUTION

This can be achieved in both the Standalone version and Visual Studio plugin through a coded solution. We will use this Grid to demonstrate how to do it:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx


As you can see this page contains a Grid. Fist we need to add this Grid to our project. From your Test Studio project, start the Recorder and navigate to the page. 

 

Using Hover Over Highlighting, highlight the Grid. Since it's an ASP .Net grid, you will see multiple options depending on which specific part of the Grid you've hovered over: 

 

 

Each of the orbs represents a specific layer of the Grid. We're interested in the GridTableView, which is the second last orb in the above image. Don't choose the actual GridView - it corresponds to a DIV element. 

 

Now bring up the pop up menu and click on "Add to Project Elements":

 

 

Going back to Test Studio, you will notice a new element has appeared in Project Elements and it will be highlighted by a yellow arrow:

 

 

Now you are ready to use this element in your coded solution. Create a new coded step and add the following lines that go through each (visible) cell in the Grid:

 

foreach (HtmlTableRow r in Pages.ASPNETGridDemo.RadGrid1Table.AllRows)
{
    foreach(HtmlTableCell c in r.Cells)
    {
        Log.WriteLine("Cell found. TextContent:"+c.TextContent); 
    }
}
 

In the above code, "Pages.ASPNETGridDemo.RadGrid1Table" references the GridTableView which we manually added to our project. Because of this you will need to change this to correspond to the actual element in your project:

 

 

Also, you can replace the following line of code with whatever logic you need to implement (currently it pastes the TextContent of each cell to the log):

 

Log.WriteLine("Cell found. TextContent:"+c.TextContent);
 

This is C# code, the VB code will follow the same logic only transcribed in the corresponding syntax. Make sure the coded steps executes at a point in your test when the page congaing the Grid is loaded in the Active Browser.