私は WatiN を使用してブラウザ アプリケーションをテストしています。
ボタンを押すと、ブラウザに新しいテーブルが追加されます。次のようになります。
<table border="0">
<tr>
<td>
<a></a>
<a></a>
<a></a>
<!-- ... -->
<a></a>
</td>
<td>
<a></a>
<a></a>
<a></a>
<!-- More anchors -->
<a></a>
</td>
<!-- More TDs -->
<td>
<a></a>
<a></a>
<a></a>
<a></a>
</td>
</tr>
</table>
特定のセルで特定のアンカーをクリックする必要があります。そのために、次の関数を実装しました。
static void pressTableCell(IE browser, string key1, string key2,int indeX,int indeY)
{
Table tbl = browser.Table(Find.By(key1,key2));
TableCell row = tbl.TableCells[indeY];
int counter = 1;
foreach (var Link in row.Elements) // I know it's weird to run with foreach and counter, but this is just for testing purposes, nobody will ever see this code except me, so i'm doing evil stuff. :)
{
if (counter == indeX)
{
Link.Click();
return;
}
counter++;
}
}
そして、例外が返されます-「border」プロパティが「0」に設定されたテーブルはありません。
名前とすべてを再確認しました。
関数呼び出し:
static void MakeItGlobal(IE browser)
{
...
//Press the button that creates the table - works. I'm certain.
pressTableCell(browser, "border", "0", 1, 2, 2);
...
}
私の質問は - なぜ例外が発生するのですか? WatiN は動的テーブルの処理方法を知りませんか?