I´m trying to get the values of TDs inside a table using WatiN. The problem is that I´m not able to select a table by Id (because it´s missing). Can I select it based on class?
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=5 BORDER=0 class="TABLEBORDER">
<TR>
<TH class=HEADTEXT>
Target
</TH>
<TH class=HEADTEXT>
Trigger<br>enabled?
</TH>
<TH class=HEADTEXT>
Account
</TH>
<TH class=HEADTEXT>
Password<br>changed?
</TH>
<TH class=HEADTEXT>
Error message<br>(if any)
</TH>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
RACF
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
USERNAME1
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
Domain Name
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
FirstName.LastName
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
NotesWeb
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
USERNAME1
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_CONTENT_BOTTOM -->
</TABLE>
There are other tables in the page. The one that I am interested is the only one that is formatted like above and I am only interested in the 3rd Column (where it says YES.. if there is a problem then it will say NO).
The table above is the only one with the class=TABLEBORDER
how can I access the 3rd column of every table row?
To identify the table, use
Find.ByClass()There are a number of ways to get the values of a particular column, but for simplicity’s sake I tend to just iterate through the table rows; easy to understand now and 6 months from now when you come back to the code.
Code: Print to the console the content of the 4th column (the Yes values in the HTML above), the loop starts at 1, not 0, so the first row is ignored as TH elements are not seen as table cells.
The above has been tested on WatiN2.1, IE9, Win7