woensdag 9 april 2008

Make TableCell handle TH elements as well

Update 9/18/2009: The described solution described below no longer works as of WatiN 2.0 beta 1. See this blog post for the new way.

Original blog text:

Going through the WatiN bug tracker on SourceForge I came along this bug report:

"When you retrieve a Table Row that contains TH elements, the TableCells collection returns empty. The reason being TableCell only recognizes TD as a valid tagname, when it should recognize TH."

I agree that TH elements probably should be seen as a TableCell as well. I'm a bit reluctant though to fix this because this will change the behavior of WatiN possibly resulting in unexpected failing tests for users of WatiN. So I did a small experiment to see if you (as a user of the WatiN API) are able to make WatiN handle TH elements as a TableCell if you need it to.

First I created this HTML table for my test


Next I wrote and ran the following unit test and..... it passed!


The trick is in the line:

TableCell.ElementTags.Add(new ElementTag("th"));

This registers the TH element as an element that can be wrapped by the TableCell class.

I tested this against the current development code and it run just fine. It probably will work as well with the current 1.2.1 and 2.0 CTP releases.

Technorati Tags:

2 reacties:

chrystal zei

in the 2.0 CTP, TableCell does not contain ElementTags. Anyone know how to get this to work in 2.0?

Jeroen zei

Hi Chrystal,

Read this blog post for the new way in WatiN 2.0 beta 1 (and higher):