Testing 如何在codedui中遍历网格元素?获取每个单元格时出错';s值

Testing 如何在codedui中遍历网格元素?获取每个单元格时出错';s值,testing,gridview,coded-ui-tests,tablerow,htmlcontrols,Testing,Gridview,Coded Ui Tests,Tablerow,Htmlcontrols,HtmlDiv hd=新HtmlDiv(UINEWTABWINDOWS INTERNEWINDOW); 添加(HtmlDiv.PropertyNames.Id,“ContentPlaceHolder1_WebPartManager1_gWPUChorizontalagentquegrid1_uchorizontalagentquegrid1_bottomWebPartHeaderMiddle1”) HtmlControl htc1=新的HtmlControl(hd); htc1.SearchPr

HtmlDiv hd=新HtmlDiv(UINEWTABWINDOWS INTERNEWINDOW); 添加(HtmlDiv.PropertyNames.Id,“ContentPlaceHolder1_WebPartManager1_gWPUChorizontalagentquegrid1_uchorizontalagentquegrid1_bottomWebPartHeaderMiddle1”)

HtmlControl htc1=新的HtmlControl(hd);
htc1.SearchProperties.Add(HtmlControl.PropertyNames.TagName,“表”);
UITestControlCollection=htc1.FindMatchingControls();
foreach(集合中的UITestControl uitabs)
{
HtmlTable ht=(HtmlTable)UITAB;
UITestControlCollection temp1;
如果(ht.Id==“ctl00\u contentplaceholder 1\u WebPartManager1\u gWPUChorizontalagentquegrid1\u uchorizontalagentquegrid1\u RadGrid1\u ctl00”)
{                   
HtmlControl htc_tr=新HtmlControl(ht);
htc_tr.SearchProperties.Add(HtmlControl.PropertyNames.TagName,“tr”);
UITestControlCollection_tr=htc_tr.FindMatchingControls();
UITestControl tr;
对于(int i=0;i
我认为在您进行了所有转换之后,有些事情变得混乱了。我尝试了以下方法,它也适用于您的场景

HtmlDiv htc1 = new HtmlDiv(UINewTabWindowsInternWindow);
htc1.SearchProperties["id"] = yourID;

HtmlTable table = new HtmlTable(htc1);
table.SearchProperties["id"] = "ct100_ContentPlaceHolder1...";

HtmlRow row = new HtmlRow(table);
row.SearchProperties["TagName"] = "TR";

UITestControlCollection rows = row.FindMatchingControls();

foreach (UITestControl myRow in rows)
{
    HtmlRow thisRow = (HtmlRow)myRow;
    // Do your thing here.
}

您甚至可以在您的行上执行您需要执行的任何操作,而无需将其从UITestControl转换回行。行的大多数属性和方法在父类中可用。

也许
tr
是一个
UIControl
子元素,它具有
HtmlRow
。我会尝试类似于
TestContext.WriteLine(tr.GetType().ToString());
的内容,以了解有关控件层次结构的更多信息。
HtmlDiv htc1 = new HtmlDiv(UINewTabWindowsInternWindow);
htc1.SearchProperties["id"] = yourID;

HtmlTable table = new HtmlTable(htc1);
table.SearchProperties["id"] = "ct100_ContentPlaceHolder1...";

HtmlRow row = new HtmlRow(table);
row.SearchProperties["TagName"] = "TR";

UITestControlCollection rows = row.FindMatchingControls();

foreach (UITestControl myRow in rows)
{
    HtmlRow thisRow = (HtmlRow)myRow;
    // Do your thing here.
}