2014-09-24 66 views
0

我正在使用我的Windows應用商店的編碼UI測試。搜索子控件

我的控制層次是:

UIPearsonPOCCommonViewFlipViewItem(XAMLFlipViewItem - > UIWebViewPane(XAMLWebViewPane) - >內容的休息

對於子控件的休息,也沒有具體的自動化ID或唯一的名稱和它們看起來像HTML控件用於例如,參照附加的圖像。

我想遍歷UIWebViewPane的孩子,並達到其具有的innerText孩子DIV。

我是相對很新的編碼的ui測試。我無法遍歷UIWebViewPane(XAMLWebViewPane)的兒童

enter image description here

回答

3

如果子控件的內部文本中是獨一無二的,你可以隨時搜索上,使用在定義父控件。例如:

public HtmlControl child() 
{ 
    HtmlControl parent = new HtmlControl(browser); 
    parent.SearchProperties["id"] = "[my id]"; 

    HtmlControl child = new HtmlControl(parent); 
    child.SearchProperties["innerText"] = "[the inner text]"; 
    return child; 
} 

如果你真的想遍歷,那麼你就必須爬行使用.GetParent()和.GetChildren()的UITestControl類的方法結構。

public HtmlControl child() 
{ 
    //First, we create an empty HtmlControl to return. 
    HtmlControl result = new HtmlControl() 

    //Specify the parent and get a collection of the children (this only goes one level, 
    // so if you have to go deeper, you'll have to nest your foreach loops and get 
    // children of the children, etc. 
    HtmlControl parent = new HtmlControl(browser); 
    parent.SearchProperties["id"] = "[my id]"; 
    UITestControlCollection children = parent.GetChildren(); 

    foreach (UITestControl child in children) 
    { 
     // If the child has the text you're looking for, then assign it to the result 
     // object and break the loop. 
     if (child.GetProperty("InnerText").ToString().Equals(searchTerm)) 
     { 
      result = (HtmlControl)child; 
      break; 
     } 
    } 

    return result; 
} 

就我個人而言,我會嘗試第一個選項。然而,你最好的選擇是要求(禮貌地)讓開發者在HTML中添加一些獨特的和靜態的標籤。