【问题标题】:Get the AutomationElement for a WPF Popup获取 WPF 弹出窗口的 AutomationElement
【发布时间】:2011-08-20 08:16:40
【问题描述】:
我正在开发一个项目,该项目使用编辑器中的弹出窗口在 ListBox 中提供对象,供用户双击以将它们添加到他们的文档中。我正在尝试使用 microsoft 提供的自动化 API 为应用程序创建自动化测试,但我无法弄清楚如何获取 Popup 控件的 AutomationElement,因为它与我的编辑器及其控件位于不同的树中。有人知道如何获取 WPF 弹出窗口的 AutomationElement 吗?
【问题讨论】:
标签:
wpf
popup
ui-automation
【解决方案1】:
我最终不得不从桌面开始,并使用一些非常具体的 PropertyConditions 和 AndCondition 来查询自动化树,并使用 TreeScope.Descendants 作为我的查询的参数。
【解决方案2】:
我从主窗口的子窗口中获得了用于弹出窗口的弹出 AutomationElement(在我的情况下为 OpenFileDialog):
// I had automationElement for main window in advance
AutomationElement mainWindow = ...
// Some condition to distinguish your popup from others
// if you may have more than one popup.
// Otherwise this condition might check ControlType == Window
Condition popupCondition = ...
var popup = mainWindow.FindFirst(TreeScope.Children, popupCondition);