Invoke-UIAButtonClick -InputObject?

Jan 25, 2013 at 8:15 PM
Edited Jan 25, 2013 at 8:15 PM

I'm curious about the -InputObject parameter - are there any examples of how it is used with Invoke-UIAButtonClick? I found something in the discussion http://uiautomation.codeplex.com/discussions/310880  but I did not really understand it.

 

Thanks!

Coordinator
Jan 25, 2013 at 8:27 PM

Hi peakbagger,

the -InputObject parameter in more than 90% of UIAutomation module's cmdlets is AutomationElement[].

"InputObject" is a relatively traditional name in MSDN for the parameter that receives data from the pipeline.

The following one-liners do exactly the same:

# variant 1
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name 1 | Invoke-UIAButtonClick;
# variant 2
$button1 = Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name 1;
$button1 | Invoke-UIAButtonClick;
# variant 3
$button1 = Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name 1;
Invoke-UIAButtonClick -InputObject $button1;
# variant 4
Invoke-UIAButtonClick -InputObject (Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name 1);

Coordinator
Jan 25, 2013 at 8:40 PM

Regarding the thread you recently dug out:

$null = Invoke-UIAButtonClick -InputObject $button1

This code should grab the reader's attention to the following:

the "$null = codeline" or [void](codeline) constructions prevent unexpected output to be returned from a function (all function statements constitute the function output)

The following piece of code equals to the previous:

[void]($button1 | Invoke-UIAButtonClick);

Coordinator
Jan 28, 2013 at 2:31 PM

A note about the -InputObject parameter (if you have not read the article as it's unnecessary to users of the module and worth reading only for developers of the module): it's not my idea to give this name to the parameter:

The -InputObject parameter is described in Cmdlet Development Guidelines as 

InputObject
Data type: Object

 Implement this parameter when the cmdlet takes input from other cmdlets. When you define an InputObjectparameter, always specify the ValueFromPipeline keyword when you declare the Parameter attribute. For more information about using input filters, see Input Filter Parameters.

I would say that the end user of the framework may but not obliged to use this parameter, or even to be aware what the parameters does: in most situations,

this parameter is the "|" character itself (i.e., "invisible" to the user):

 

Get-UIAWindow -n calc* | Get-UIAButton -n [1-9] | Invoke-UIAButtonClick;
# or
Get-UIAWindow -pn calc | Invoke-UIARegisterWindowOpenedEvent -EventAction {};

 

In the first line of code, a window object AutomationElement[] is put into the -InputObject parameter of the Get-UIAButton cmdlet (1 element). The -InputObject parameter of the Invoke-UIAButtonClick cmdlet is an array AutomationElement[] consisting of 9 elements in the order that Windows preferred.

In the second line of code, a window object (AutomationElement[], 1 element or several elements if more than one calc.exe is running) is/are put into the -InputObject parameter of the Invoke-UIARegisterWindowOpenedEvent cmdlet.

Jan 28, 2013 at 5:47 PM

Thank you XinLiu - your examples helped a lot.