![](/img/trans.png)
[英]Microsoft ui-automation not able to fetch chrome's context menu elements
[英]UI-Automation cmdlet not finding the control
我正在尝试使用MSFT提供的UI自动化框架来测试WPF应用程序。 编写了一些powershell脚本,这些脚本调用了为操纵应用程序的可视控件而创建的cmdlet。
我的应用程序中有一个DropDown,其中有一个条目“ DropDownEntry”。 在我的cmdlet中,我尝试执行以下操作:
AutomationElement getItem = DropDown.FindFirst(TreeScope.Descendants,
new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.ListItem),
new PropertyCondition(AutomationElement.NameProperty, "DropDownEntry",PropertyConditionFlags.IgnoreCase)));
上面给出的代码片段在执行时返回“ null”,这实际上意味着上面给出的逻辑无法找到我的下拉条目。
有人可以告诉我为什么会这样吗? 我检查了控件的名称和值。 一切似乎都井井有条。 我不确定为什么会这样。 任何帮助将非常感激。
谢谢
由于这是您要自动执行的DropDown控件,因此可能只有在DropDown下拉之前,子项才可以通过UIAutomation使用。
您需要从DropDown元素获取ExpandCollapse模式,然后调用其Expand方法。
我创建了一些扩展方法来帮助掌握模式。 这是一个例子
public static class PatternExtensions
{
public static ExpandCollapsePattern GetExpandCollapsePattern(this AutomationElement element)
{
return element.GetPattern<ExpandCollapsePattern>(ExpandCollapsePattern.Pattern);
}
public static T GetPattern<T>(this AutomationElement element, AutomationPattern pattern) where T : class
{
object patternObject = null;
element.TryGetCurrentPattern(pattern, out patternObject);
return patternObject as T;
}
}
像这样使用它:
DropDown.GetExpandCollapsePattern().Expand()
然后,您可以执行原始代码以找到子元素。
如果还没有,您可能需要使用UISpy检查应用程序以验证属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.