C# 编码的UI HtmlTable的行和单元格属性为空
我尝试自动化测试,尝试访问HtmlTable对象,但这并不是那么容易。。如果我将其添加到UImap,设计器文件将其显示为HtmlTable,但我无法从地图中找到它。 如果我尝试手动查找它,它可以工作,但是Rows和Cells属性为null,但是CellCount和RowCount显示的值正确。 我访问单元格的唯一方法是将HtmlTable分离为两个HtmlCustom控件。 第一个标记名是THEAD,第二个标记名是TBODY 分离后,我可以使用GetChildren函数获取子行,但在某些情况下,GetChildren返回null。。 我找不到关于这个问题的任何信息。我做错了什么 更新 大多数情况下,GetCell函数工作正常,并返回单元格本身,但在少数情况下,它无法找到5%的单元格。就像GetChildren函数一样。但这真的很烦人。C# 编码的UI HtmlTable的行和单元格属性为空,c#,testing,automated-tests,coded-ui-tests,htmltable-control,C#,Testing,Automated Tests,Coded Ui Tests,Htmltable Control,我尝试自动化测试,尝试访问HtmlTable对象,但这并不是那么容易。。如果我将其添加到UImap,设计器文件将其显示为HtmlTable,但我无法从地图中找到它。 如果我尝试手动查找它,它可以工作,但是Rows和Cells属性为null,但是CellCount和RowCount显示的值正确。 我访问单元格的唯一方法是将HtmlTable分离为两个HtmlCustom控件。 第一个标记名是THEAD,第二个标记名是TBODY 分离后,我可以使用GetChildren函数获取子行,但在某些情况下,
我编写了一个带有try-catch块的小递归函数来捕获NullReferenceException,并一次又一次地尝试获取单元格,但这没有多大帮助。您可以使用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;
}
谢谢你的回答 我终于解决了这个问题。Solved不是一个正确的词,但可以理解为什么属性和函数如此随机地工作 我尝试测试的网页有一些动态JS元素,页面每3秒钟刷新一次。这就是HtmlTable异常行为的原因
现在我尝试在浏览器中以某种方式禁用此自动刷新。如果父控件必须是表控件,则在父控件上具有相同的方法-GetCell,您不需要自己编写它…我编写了自己的GetCell函数,但HtmlTable有自己的GetCell属性。它们都不起作用。GetCell属性抛出一个NullReference异常,我的手写GetCell方法什么都不做,只返回一个null。您可能需要调整搜索属性,使表可以定位。不需要做HtmlCustom。如果页面上只有一个表,那么更巧妙的方法是从SearchFilter中删除所有内容,在SearchProperties中只保留标记名为表,并删除其他搜索属性。它肯定能找到桌子。之后,GetCell和GetRow应该可以正常工作。我没有任何搜索属性。我可以手动定位表,问题是单元格和行为空。RowCount和CellCount工作正常。
//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;
}