简体   繁体   中英

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM