首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAutomation FlaUI -检测应用程序级别上打开的窗口

UIAutomation FlaUI -检测应用程序级别上打开的窗口
EN

Stack Overflow用户
提问于 2022-06-03 07:48:00
回答 2查看 393关注 0票数 0

我正在使用FlaUI进行测试自动化,到目前为止它工作得很好。现在,我正在尝试检测打开的窗口,虽然普通的UIAutomation提供了为"AutomationElement.RootElement“注册一个均衡器,但我无法找到一种将其转换为FlaUI的方法,因为它总是期望有一个AutomationElement。我只能想到MainWindow,但是随着Splash,Login,Enviroment-选择等等,这会发生变化。

这就是我现在所拥有的,但当我打开一扇窗户时,它不会开火:

代码语言:javascript
复制
Window win = app.GetMainWindow(automation, TimeSpan.FromSeconds(5));
                UIA3AutomationEventHandler automationEventHandler = new UIA3AutomationEventHandler(win.FrameworkAutomationElement, automation.EventLibrary.Window.WindowOpenedEvent, TestAction);
                automation.NativeAutomation.AddAutomationEventHandler(automation.EventLibrary.Window.WindowOpenedEvent.Id,automation.NativeAutomation.GetRootElement(), (Interop.UIAutomationClient.TreeScope)TreeScope.Descendants, null, automationEventHandler);

遵循工作平面UIAutomation代码:

代码语言:javascript
复制
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
                AutomationElement.RootElement,
                TreeScope.Descendants,
                someDelegate);

任何帮助都将不胜感激!谢谢大家!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-06-03 14:41:25

FlaUI在automation对象(即RootElement )上有一个GetDesktop方法。你应该能够在那里注册一个事件。

票数 1
EN

Stack Overflow用户

发布于 2022-06-07 08:36:10

在“Roemer”的帮助下,我成功了。非常感谢!

代码语言:javascript
复制
using (var automation = new UIA3Automation())
{
            AutomationElement root = automation.GetDesktop();
            UIA3AutomationEventHandler automationEventHandler = new UIA3AutomationEventHandler(root.FrameworkAutomationElement,
                    automation.EventLibrary.Window.WindowOpenedEvent, HandleClickOnceDialogs);
            automation.NativeAutomation.AddAutomationEventHandler(automation.EventLibrary.Window.WindowOpenedEvent.Id, 
                                                            root.ToNative(),
                                                                  (Interop.UIAutomationClient.TreeScope)TreeScope.Descendants,
                                                        null, automationEventHandler);
}

private void HandleClickOnceDialogs(AutomationElement element, EventId id)
{
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72486331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档