I am trying to click a button using invoke pattern.
InvokePattern ipAddMPButton = (InvokePattern)aeAddMPButton.GetCurrentPattern(InvokePattern.Pattern);
try
{
ipAddMPButton .Invoke();
}
catch (System.Runtime.InteropServices.COMException e)
{
// TODO
}
It throws COMException and I can't figure out why?
When I run this code, the button is actually pressed and the functionality works well. But then it just stops for some time, and throws this exception.
Actually I have found that this is already discussed here: https://social.msdn.microsoft.com/Forums/en-US/673bba3d-27b3-4374-b049-0d2e8ec5e462/hang-with-invokepattern-invoke-in-virtual-pc?forum=windowsaccessibilityandautomation . To summarize, Winforms opening of modal dialog does not play nicely with UIAutomation as it does not return from the Invoke command and only creates the modal dialog which of course prevents it from completing the operation. The proposed solution is to spawn a background thread and activate Invoke (or any other operation) from that thread. I also suggest enforcing some kind of timeout for the completion of the operation as it can be lengthy in some circumstances.
Try checking aeAddMPButton.GetAllSupportedPatterns() and then try invoking then..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With