如何遍历codedui中的网格元素?获取每个单元格的值时会出错

时间:2014-06-06 07:35:00

标签: testing gridview coded-ui-tests tablerow htmlcontrols

HtmlDiv hd = new HtmlDiv(UINewTabWindowsInterneWindow);             hd.SearchProperties.Add(HtmlDiv.PropertyNames.Id,“ContentPlaceHolder1_WebPartManager1_gwpucHorizo​​ntalAgentQueueGrid1_ucHorizo​​ntalAgentQueueGrid1_bottomWebPartHeaderMiddle1”);

        HtmlControl htc1 = new HtmlControl(hd);
        htc1.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "TABLE");
        UITestControlCollection collection = htc1.FindMatchingControls();


        foreach (UITestControl uitabs in collection)
        {

            HtmlTable ht = (HtmlTable)uitabs;
            UITestControlCollection temp1 ;
            if (ht.Id == "ctl00_ContentPlaceHolder1_WebPartManager1_gwpucHorizontalAgentQueueGrid1_ucHorizontalAgentQueueGrid1_RadGrid1_ctl00")
            {                   

                HtmlControl htc_tr = new HtmlControl(ht);
                htc_tr.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "TR");
                UITestControlCollection collection_tr = htc_tr.FindMatchingControls();

                UITestControl tr;
                for (int i = 0; i < collection_tr.Count; i++)
                {
                    tr= collection_tr[i];

                   // HtmlRow hr = (HtmlRow)tr;  //getting error not able to cntrol htmlol to html row

1 个答案:

答案 0 :(得分:0)

我会假设在您正在进行的所有转换后,某些事情变得混乱。我已经尝试了以下内容,它也适用于您的场景。

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转换回行的情况下执行您需要执行的任何操作。该行的大多数属性和方法都可以在父类中使用。