【问题标题】:C# wait user interaction with WhiteC# 等待用户与 White 的交互
【发布时间】:2017-02-17 20:43:25
【问题描述】:
我正在考虑将 White 用于我的简单 windows ui 自动化。首先,我使用System.Diagnostics.Process 从我的应用程序运行外部应用程序。当外部应用程序打开时会给我一个对话框,用户在其中插入一些文本并单击 OK 按钮。我需要等到对话框关闭或检测到单击确定按钮。我所需要的只是一些迹象表明用户已完成该对话框,我可以继续我的自动化任务。
有什么办法可以用怀特做到这一点吗?也欢迎任何其他选择!
【问题讨论】:
标签:
c#
automation
white-framework
【解决方案1】:
您可以在该对话框上设置标题,并安排计时器在主窗口的子窗口中查找子窗口。如果没有找到,您可以继续。 应该工作。
【解决方案2】:
另一种方式:
using System.Windows.Automation;
Automation.AddAutomationEventHandler(
WindowPattern.WindowClosedEvent,
AutomationElement.RootElement, // set correct value here
TreeScope.Children, // check the value is correct
(sender, e) =>
{
var element = sender as AutomationElement;
if (element.Current.Name != "Form Title")
return;
Automation.RemoveAllEventHandlers(); // remove event handler
// Your code here
// CodeToRunAfterWindowClosed();
});