【发布时间】:2016-01-30 00:05:49
【问题描述】:
我正在尝试使用 System.Windows.Automation 库进行一些 UI 测试,并且能够取得一些进展,但是我无法订阅在我的应用中创建弹出窗口的事件。我尝试在根(桌面对象)以及窗口上使用Automation.AddStructureChangedEventHandler,但这不起作用。我也尝试使用不同的范围,但也没有帮助。
AutomationElement desktop = AutomationElement.RootElement;
AutomationElement app = desktop
.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty,
"Name of the App", PropertyConditionFlags.IgnoreCase));
ActivateWindow(app);
AutomationElement appWindow = app
.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Window));
// Find a button that opens a popup window and click it
AutomationElement button = appWindow
.FindFirst(TreeScope.Children, Condition.TrueCondition)
.FindAll(TreeScope.Children, Condition.TrueCondition)[8];
MoveMouseToAndClick(button);
Automation.AddStructureChangedEventHandler(desktop, TreeScope.Descendants, setupWindowOpen);
setupWindowOpen 处理程序有时会触发,但看起来其他应用程序会发生这种情况,而不是我的(我在发件人元素对象上看到 Internet Explorer id)。
提前致谢。
【问题讨论】:
标签: c# windows testing ui-automation