2016-05-05 48 views
0

我有一个Web应用程序。我使用编码的ui编写自动化测试来测试应用程序。通过在编码的UI中筛选属性来选择UI元素

我有一个文本框的下拉列表。在输入文本框中的值时,下拉框中的值将根据输入的文本进行过滤。

enter image description here

如果我喜欢里面“管理员”文本框中键入时,我会得到下面这样的选择:

enter image description here

,我需要捕捉显示的两个选项。

但使用IE开发工具(F12),我无法捕获过滤的选项,因为显示的选项没有任何独特的属性(如下所示)。以及没有显示的选项有一类=“隐藏”属性

任何方式来捕捉由像应用某种过滤器中显示的元素“选择UI元素,它的类!=隐藏”

谢谢提前!!

enter image description here

回答

0

HI请尝试以下代码将你的作品或not.By遍历所有那些具有类=“隐藏”

WpfWindow mainWindow = new WpfWindow(); 
      mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden"); 
      UITestControlCollection collection = mainWindow.FindMatchingControls(); 
      foreach (UITestControl links in collection) 
      { 

       HtmlHyperlink mylink = (HtmlHyperlink)links; 

       Console.WriteLine(mylink.InnerText); 
      } 
+0

感谢您的回答。但是我希望没有classname的控件是“隐藏的”。 – Maltesh

+0

好吧,那么你必须添加一些动态ID,或者你需要在运行时在下拉列表中添加一些属性,这样你就可以确定控制...而没有他们无法捕捉到。 – stylishCoder

0

我不知道控制有一种方法要通过搜索属性来完成,但还有其他方法。

其中一种方法是蛮力差异收集。找到所有的列表项目,然后找到隐藏的项目并做出改变。

HtmlControl listControl = /* find the UL somehow */ 

HtmlControl listItemsSearch = new HtmlControl(listControl); 
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li"); 

HtmlControl hiddenListItemsSearch = new HtmlControl(listControl); 
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li"); 
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden"); 

var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls()); 

您只能一次迭代该集合,所以如果您需要迭代多次,请创建一个返回此搜索的函数。

var listItemsFunc =() => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls()); 

foreach(var listItem in listItemsFunc()){ 
// iterate 1 
} 

foreach(var listItem in listItemsFunc()){ 
// iterate 2 
} 

我会考虑这样做的另一种方式是过滤器的基础上有一个可点击的点和占用空间的屏幕(即不隐藏)上的控件。

listItemsSearch.FindMatchingControls().Where(x => { 
    try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; } 
});