2014-06-06 51 views
0

HtmlDiv hd = new HtmlDiv(UINewTabWindowsInterneWindow); hd.SearchProperties.Add(HtmlDiv.PropertyNames.Id,「ContentPlaceHolder1_WebPartManager1_gwpucHorizo​​ntalAgentQueueGrid1_ucHorizo​​ntalAgentQueueGrid1_bottomWebPartHeaderMiddle1」);如何遍歷codedui中的網格元素?獲取每個單元格的值時出現錯誤

 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 
+0

也許'tr'是'UIControl',它有一個'HtmlRow'作爲子元素。我會嘗試像'TestContext.WriteLine(tr.GetType()。ToString());'來了解更多關於控制層次的內容。 – AdrianHHH

回答

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將其轉換回行做你行的任何動作。行的大多數屬性和方法在父類中可用。

相關問題