2014-09-24 70 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中添加一些独特的和静态的标签。