[英]How to make sure that button has been clicked?
Is there a simple way to check if my OK button was pressed? 有没有一种简单的方法来检查是否按下了我的“确定”按钮? Most of the times it is working perfectly, but 1 in 100 it fails:
在大多数情况下,它运行良好,但是每100个失败了:
AutomationElement rl = SomeMethod();
if (rl.Current.Name == "OK" && rl.Current.ControlType == ControlType.Button)
{
InvokePattern click = (InvokePattern)rl.GetCurrentPattern(InvokePattern.Pattern);
click.Invoke();
}
I wonder why. 我想知道为什么。
To get a notification after your button has been pressed you can register an AutomationEventHandler via 要在按下按钮后获得通知,可以通过以下方式注册AutomationEventHandler:
Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, AutomationElement yourAE,TreeScope.Element, new AutomationEventHandler(OnStartInvoke));
private static void OnStartInvoke(object src, AutomationEventArgs e)
{
//logic
}
you could use this in order to verify that the button has been clicked also. 您可以使用它来验证是否还单击了该按钮。 Invoke the button in a scheduler (with a certain timeout) until you enter your OnStartInvoke.
调用调度程序中的按钮(具有一定的超时时间),直到输入OnStartInvoke。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.