This project is read-only.
If a control does not support InvokePattern, it is not a big problem. We have for this purpose the Invoke-UIAcontrolClick cmdlet:
Get-UIAWindow -pn calc | Get-UIAButton -Name 1 | Invoke-UIAControlClick;
Traditionally, the Invoke-UIAControlClick cmdlet supports a number of input controls:
Get-UIAWindow -pn calc | Get-UIAButton -Name [1-9] | Invoke-UIAControlClick;
This cmdlet pipelines the input to the output, if no errors raised:
Get-UIAWindow -pn calc | Get-UIAButton -Name [1-9] | Invoke-UIAControlClick | Read-UIAControlName;

The Invoke-UIAControlClick cmdlet uses Win32 API calls (SendMessage/PostMessage, for example) working only with controls that have handles. However, the Invoke-UIAControlClick cmdlet accepts any AutomationElement, with or without a handle. How does this work? The cmdlet accepts a control, and if the input control has handle, the cmdlet hits the geometrical center of the control.
If a control has no handle, the cmdlet gets its parent, if there is no handle too, its respective parent unless a control with handle is found (even if it is the process's window). After that the cmdlet calculates the position that corresponds to the geometrical center of the input control and hits there. So works click on any control with the API call that works only with handles.

The Invoke-UIAControlClick cmdlet can also be used in conditional statements, but we should remember that the SendMessage call does not return a value we could use as a result flag. Thus, the $true result means only that no network errors occured, or the system has not been shut down, etc.
# we are not sure that click was successful
if (Get-UIAWindow -pn calc | Get-UIAButton -Name 1 | Invoke-UIAControlClick -PassThru:$false) {
    # on probably successful click
# the assume that the click was successful
if ($null -ne (Get-UIAWindow -pn calc | Get-UIAButton -Name 1 | Invoke-UIAControlClick)) {
    # on probably successful click

Tags: ControlType.Window, ControlType.Button, SendMessage

Last edited Jan 19, 2013 at 5:21 PM by xinliu, version 3


No comments yet.