我正在使用FlaUI进行测试自动化,到目前为止它工作得很好。现在,我正在尝试检测打开的窗口,虽然普通的UIAutomation提供了为"AutomationElement.RootElement“注册一个均衡器,但我无法找到一种将其转换为FlaUI的方法,因为它总是期望有一个AutomationElement。我只能想到MainWindow,但是随着Splash,Login,Enviroment-选择等等,这会发生变化。
这就是我现在所拥有的,但当我打开一扇窗户时,它不会开火:
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代码:
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
AutomationElement.RootElement,
TreeScope.Descendants,
someDelegate);任何帮助都将不胜感激!谢谢大家!
发布于 2022-06-03 14:41:25
FlaUI在automation对象(即RootElement )上有一个GetDesktop方法。你应该能够在那里注册一个事件。
发布于 2022-06-07 08:36:10
在“Roemer”的帮助下,我成功了。非常感谢!
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)
{
}https://stackoverflow.com/questions/72486331
复制相似问题