how to find items on a table Grid using WATIN
I am having some issues trying to find item on a table - it's either null or I am getting an array out of bounds exception. This is what i am trying to do.
This is sample html that I am parsing from the page....
<table id="ctl00__defaultCont__ctrlHeader__ctrlHeader_p_Providerd33">
<tr>
<td class="w90 ta-right lbl">
<span>Provider ID</span>
</td>
<td class="fieldWithNoBorderClass">
<div id="ob_iT_providerIDContainer" class="ob_iTCN" style="width:220px;"><div class="ob_iTL"></div><div class="ob_iTR"></div><div class="ob_iTC"><input name="ctl00$_defaultContent$_ctrlHeader$_ctrlHeader$_providerID" type="text" value="P13040620" id="ctl00__defaultContent__ctrlHeader__ctrlHeader__providerID" class="ob_iTIE" /></div><div class="ob_iCallbackScript" style="display:none;"></div></div>
</td>
</tr>
Here is what I started out with:
I am basically trying to find the PROVIDER ID. For example...
Table table = browser.Table(Find.ById("ctl00__defaultContent__ctrlHeader__ctrlHeader_p_Provider3"));
TableRowCollection tableRows = table.TableRows;
TableRow row = tableRows[3];
ElementCollection rowData = row.Elements;
string name = rowData[0].OuterText;
string membername = rowData[1].OuterText;
开发者_运维知识库
I do something like this, and it works on one of my projects. Maybe this will give you a clue.
NOTE: Watin table access is VERY slow.
Table table = browser.Table("ctl00_defaultContent_ctrlHeader__ctrlHeader_p_Provider3");
if (table == null)
{
DebugLog("Could not find table");
throw new Exception("Results table missing.");
}
TableRow tr = table.TableRows[3];
while( tr != null)
{
string words = tr.TableCells[1].Text;
tr = (TableRow)tr.NextSibling;
}
You need to search the item one by one:
Table table = browser.Table(Find.ById("ctl00_defaultContent_ctrlHeader__ctrlHeader_p_Provider3"));
for (int i = 0; i < table.TableBodies[bodyIndex].TableRows.Count; i++)
{
if (table.TableBodies[0].OwnTableRows[i].TableCells[headerNameColumn].Text == "Provider id...")
{
// do something
}
}
精彩评论