I am trying to automate UI navigation for an application which itself makes calls to the coms.
When I automate the click (which runs a search to see which devices are online), I get the following popup error:
An outgoing call cannot be made since the application is dispatching an input-synchronous call.
The line of code that fails is as follows:
Get-UiaButton -AutomationId '136' -Class 'Button' -Name 'Search Now' -Win32 | Invoke-UIAButtonClick
The research I have done suggests that it is threading apartment problem. Powershell 2 natively runs in MTA. While powershell 3/4 natively runs in STA. I tried running the command in both environments and it fails the same way.
Further research suggests that something is is trying to SendMessage from the wrong type of thread. The only messages that I have control over are the ones that are generated by the Get-UIAButton
call. I have tried turning off the object messages using
[UIAutomation.Preferences]::UseElementsPatternObjectModel = $false
[UIAutomation.Preferences]::UseElementsSearchObjectModel = $false
However two lines still make it through
Current : UIAutomation.UiElementInformation
__interceptors : {UIAutomation.MethodSelectorAspect, UIAutomation.ErrorHandlingAspect}
I couldn't find any other preferences that looked like they would turn off the rest.
I have tried redirecting the output to | Out-Null
... and it still produces the same error.
I have also tried running the command under a second powershell instance.
powershell.exe -mta -nologo -noprofile -executionpolicy bypass -command "ipmo C:\Users\Admin\Downloads\UIAutomation.0.8.7B3.NET35b\UIAutomation.dll; Get-UiaButton -AutomationId '136' -Class 'Button' -Name 'Search Now' -Win32 | Invoke-UIAButtonClick"
I'm not really sure what to try next. Honestly, I may just try to automate this click using Autoit.