0

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.

manuell
  • 7,528
  • 5
  • 31
  • 58
Dee Dee
  • 1
  • 3
  • In order to answer this, we would need to know more about the context of the code that calls `Get-UiaButton`. There's a relevant question [here](http://stackoverflow.com/questions/6610202/com-outbound-call-results-in-an-outgoing-call-cannot-be-made-since-the-applicat) - essentially, you cannot call UIA (or any cross-process COM) from code that's invoked via SendMessage. – Eric Brown Mar 16 '15 at 18:32
  • Thank you. What I don't understand is what is calling the SendMessage. So the Get-UiaButton is just a part of a normal uiautomtion powershell script. One call after another to make clicks in a windows application. All of those clicks work fine (clicks that set up the parameters to do a search in the application), until the "Search Now" button is clicked. Now I know that that application makes calls to the COMMs to assemble information for the search, but should the powershell script and the windows application be interfering with each other? – Dee Dee Mar 17 '15 at 19:33
  • That's why we would need to see the code that's calling `Get-UiaButton`. Also, it's *possible* that the problem is in the application under test. If it's spending a lot of time in a handler invoked by sendmessage (perhaps running a nested message loop), then the UIA callback (needed to send the automation data back from the target application to your powershell script) might be hitting the outbound call limitation. Again, we would need more information to tell. – Eric Brown Mar 17 '15 at 19:38
  • The windows application is third party. I'm not really testing it so much as automating data collection to then use to verify our code against. Are there debugging tools that would allow me to investigate what that application is doing or what resources it is hogging without having access to the source code? My powershell script is literally a long list of Get-UIA**** | Invoke-Uia*** inside of try catches. I'm happy to link it if you think it will help. – Dee Dee Mar 17 '15 at 21:59
  • Ok. One thing you might try is using `Invoke-UIAControlClick` to send mouseclicks instead of directly invoking the button. Or does the button not available before `Get-UiaButton` fails? – Eric Brown Mar 18 '15 at 23:16

0 Answers0