我尝试自动化测试,尝试到达一个HtmlTable
对象,但这并不容易。如果我将它添加到UImap
,设计器文件将其显示为 HtmlTable,但我无法从地图中找到它。如果我尝试手动找到它,它可以工作,但 Rows 和 Cells 属性为空,但CellCount
andRowCount
显示正确的值。我可以到达单元格的唯一方法是将 HtmlTable 分隔为两个 HtmlCustom 控件。第一个的“ TagName
”是“ THEAD
”,第二个是“ TBODY
”。
HtmlCustom parent = new HtmlCustom(htmlTable);
parent.SearchProperties.Add("TagName","TBODY");
parent.SearchProperties.Add("ClassName","HtmlTag.TBODY");
var firstchild = parent.GetChildren();
foreach(var secondchild in firstchild)
{
var thrdchild = secondchild.GetChildren();
foreach (var cells in thrdchild)
{
//do sg
}
}
分离后,我可以获得具有该GetChildren()
功能的孩子(基本上是行),但在某些情况下,GetChildren
回报null
..我找不到关于这个问题的任何信息。我究竟做错了什么?
更新
大多数情况下,该GetCell
函数正常工作并返回单元格本身,但在少数情况下(5%)它找不到单元格。就像GetChildren
函数一样。但这真的很烦人。我用try catch块编写了一个小递归函数来捕获NullReferenceException
并一次又一次地尝试获取单元格,但这无济于事..