Access table rows

Class library usage, coding and language questions.
Posts: 2
Joined: Thu Feb 21, 2013 10:20 am

Access table rows

Post by LynchDev » Thu Feb 21, 2013 10:55 am

I have a <table> on a webpage that can have a variable amount of table rows, and I would like to know how I could iterate through these and pull out the data inside each.

In addition, the table's ID tag is a GUID, so essentially the table has no identifying information. So the only way I can access the table is to keep a reference to the first row in the Ranorex repository, then backtrack to the table tag and go from there.

The current XPath I am using:

Code: Select all

As you can see I am skipping over the table id with a regex, and then finding the first row with a regex that matches data with 'aaa' or 'bbb'.

To sum up, some pseudo code for what I am trying to do:

Code: Select all

if (repo.tableData.Exists)
    var table = repo.tableData.ParentRow.ParentTable;
    var listOfInvalidCellsFound;
    loop (rows in table)
         loop (cells in row)
             if (aaabbbRegex.IsMatch(cell.Text))
Is this possible with the API?

ps. I'm open to using other ideas, but this is the only way I found that might work (new to Ranorex API)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12169
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: Access table rows

Post by Support Team » Mon Feb 25, 2013 6:52 pm


I would use the following code to iterate over cells in a table.
Please take a look at it and adjust it to meet your needs.
var rows = Host.Local.Find<TrTag>("/dom[@domain='' and @caption='Ranorex Test Page']//table/tbody/tr/td[@innertext~'1']/../../tr");
int rowNum = 1;

foreach (var row in rows)
	Report.Info("Row: " + rowNum);				
	var cells = row.FindDescendants<TdTag>();
	foreach (var cell in cells)
		Report.Info("Cell: " + cell.InnerText);

Markus (T)