Performing a click

To click on a control, use a cmdlet with verb 'Invoke' and part of noun 'Click':
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name 1 | Invoke-UIAButtonClick;
In the sample above we clicked on the button 1. Now, we click on butttons 1,2, and 3:
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name [1-3] | Invoke-UIAButtonClick;
How does this work? The Get-UIAButton returns three controls with names 1, 2, and 3. The Invoke-UIAButtonClick cmdlet receives three controls and clicks on each.

In versions prior to 0.8.3, to click on a control that does not support InvokePattern, we should use the Invoke-UIAControlClick cmdlet:
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name [1-3] | Invoke-UIAControlClick;

Reading and writing text

For these examples, let's turn Calculator in the Mortgage mode:
ReadingWritingText001.jpg
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem -Name View | Invoke-UIAMenuItemExpand | Get-UIAMenuItem -Name Worksheets | Move-UIACursor -X 3 -Y 3 | Get-UIAMenuItem -Name Mortgage | Invoke-UIAMenuItemClick;

Writing text

We will now write numbers into Edit elements, supposing that Calculator is running and prepared as shown above.
Get-UIAWindow -pn calc;
Get-UIAEdit -Name Purchase*price | Set-UIAEditText -Text 100;
Get-UIAEdit -Name Down*payment | Set-UIAEditText -Text 10;
Get-UIAEdit -Name Term*years* | Set-UIAEditText -Text 10;
Get-UIAEdit -Name Interest*rate* | Set-UIAEditText -Text 2;
Get-UIAButton -Name Calc* | Invoke-UIAButtonClick;
ReadingWritingText002.jpg

Getting text

Get-UIAWindow -pn calc;
Get-UIAEdit -Name Monthly*payment | Get-UIAEditText;

Selecting an item

Scrolling an item

ScrollItemPattern helps much if a control of interest is hidden. Here we run services.msc (via Run as Administrator or under credentials of an administrative account), on a Windows 7 box, where the BranchCache service row is out of the application screen:
Start-Process services.msc -PassThru | Get-UIAWindow | Get-UIADataGrid | Get-UIADataItem -Name BranchCache | Invoke-UIADataItemScrollItem | Invoke-UIAControlContextMenu | Get-UIAMenuItem -Name Properties | Invoke-UIAMenuItemClick;

Tags: ControlType.Window, ControlType.Button, InvokePattern, SendMessage, ExpandCollapsePattern, ControlType.MenuItem, move cursor, ScrollItemPattern

Last edited Jan 19, 2013 at 6:37 AM by xinliu, version 8

Comments

No comments yet.