0

我尝试自动化测试,尝试到达一个HtmlTable对象,但这并不容易。如果我将它添加到UImap,设计器文件将其显示为 HtmlTable,但我无法从地图中找到它。如果我尝试手动找到它,它可以工作,但 Rows 和 Cells 属性为空,但CellCountandRowCount显示正确的值。我可以到达单元格的唯一方法是将 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并一次又一次地尝试获取单元格,但这无济于事..

4

2 回答 2

0

感谢您的回答。

最后我解决了这个问题。已解决不是一个正确的词,但可以理解为什么属性和函数如此随机地工作。

我尝试测试的网页有一些动态 JS 元素,页面每 3 秒刷新一次。这就是HtmlTable.

现在我尝试在浏览器中以某种方式禁用此自动刷新。

于 2015-09-07T16:05:42.260 回答
0

您可以使用 HtmlCell 函数

//for verification

var cell=GetCell(2,1);

//Now you can use the assert class for verification

Assert.areequal("CodedUi ", cell.innertext,"values are not matched");

HtmlCell GetCell(UITestControl parent, int row, int column)
{ 
  var cell= new htmlcell(parent);
  cell.Searchproperties.Add(HtmlCell.Propertynames.Rowindex,row);
  cell.Searchproperties.Add(HtmlCell.Propertynames.Columnindex,column);
   retun cell;
}
于 2015-09-05T08:27:50.733 回答