Tag Archives: HtmlTable

Our Friend, CopyFrom()

Ok, so in your CUIT (Coded UI Test) you’ve successfully completed a search for an HTML table in the app. The object found is a UITestControl, which is a very generic object.

Though the UITestControlobject has data for an HTML table, it is largely unaware of that: it does not offer properties and methods that are table-oriented. (You can see its properties and methods in the doc for UITestControl).

What if it could be made into something more table-like? Well, we’re in luck!

There’s another class, HtmlTable, that has all the properties and methods we’d want for a table. You can see those properties and methods at the doc for HtmlTable.

This class is especially useful because it hides a lot of troublesome wrinkles: Is the first child of the table element a row element? Or a table header element? When you access the rows via property HtmlTable.Rows, it doesn’t matter. The first row is the first row, and not the header (if there is one).

So how to convert from the one to the other? CopyFrom!

If the UITestControl table you found is in variable control, you would write (in C#)


HtmlTable table = new HtmlTable();
table.CopyFrom(control);

And that’s it! You can work with the table as an HtmlTable object instead of the generic UITestControl object.

The really good news is that this same conversion is available for dozens of HTML-oriented classes. See a listing of many of the relevant classes in the doc for HmtlControl (in the section “Inheritance Hierarchy” at the top, click link More...).

Advertisements