2014-06-06 1 views
0

HtmlDiv hd = new HtmlDiv (UINewTabWindowsInterneWindow); hd.SearchProperties.Add (HtmlDiv.PropertyNames.Id, "ContentPlaceHolder1_WebPartManager1_gwpucHorizontalAgentQueueGrid1_ucHorizontalAgentQueueGrid1_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 
+0

아마도'tr'은'HtmlRow'를 자식 요소로 갖는'UIControl'입니다. 컨트롤 계층 구조에 대해 더 배우려면'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으로 변환하지 않고도 할 필요가 당신의 행에 어떤 작업을 수행 멀리 얻을 수 있습니다. 행의 대부분의 속성과 메서드는 부모 클래스에서 사용할 수 있습니다.

관련 문제