Microsoft UI Automation: Throw Pattern Exception

I am trying to press a button using a call pattern.

InvokePattern ipAddMPButton = (InvokePattern)aeAddMPButton.GetCurrentPattern(InvokePattern.Pattern); try { ipAddMPButton .Invoke(); } catch (System.Runtime.InteropServices.COMException e) { // TODO } 

It throws a 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 a while and throws this exception.

+5
source share
2 answers

In fact, I found that this is already being 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, opening a Winforms modal dialog does not work very well with UIAutomation, since it does not return from the Invoke command and only creates a modal dialog, which, of course, does not allow it to perform the operation. The proposed solution is to create a background thread and activate Invoke (or any other operation) from this thread. I also suggest applying some kind of timeout to complete the operation, as in some cases it can be lengthy.

+2
source

Try checking aeAddMPButton.GetAllSupportedPatterns () and then try activating it.

+1
source

Source: https://habr.com/ru/post/1201379/


All Articles