UIAutomation 0.8.6

Rating: No reviews yet
Downloads: 0
Updated: Mar 13, 2013 by xinliu
Dev status: Planning Help Icon

Available Downloads

There are no downloads associated with this release.

Release Notes

Added:

  • the Get-UIAWindow cmdlet now supports -AutomaitonId and -Class parameters (with or without the -Name parameter)
Start-Process calc;
sleep -Milliseconds 500;
# powershell.exe
Get-UIAWindow -Class Console* | Read-UIAControlName;
# calc.exe
Get-UIAWindow -Class *frame* | Read-UIAControlName;
  • the -Recurse parameter to the Get-UIAWindow cmdlet
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem -Name help | Invoke-UIAMenuItemExpand | Get-UIAMenuItem -Name *about* | Invoke-UIAMenuItemClick;
# two windows
Get-UIAWindow -pn calc -Recurse | Read-UIAControlName;
# the About Calculator window
Get-UIAWindow -pn calc -n *about* | Read-UIAControlName;
  • the -Recurse parameter in the Get-UIAWindow cmdlet is set $false by default for code compatibility. In new code (-pn, -pid, -InputObject parameters + -n), it is set $true by default:
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem help | Invoke-UIAMenuItemExpand | Get-UIAMenuItem -n *about* | Invoke-UIAMenuItemClick;
# -Recurse = $false, though you can set it $true
Get-UIAWindow -pn calc;
Get-UIAWindow -pid (Get-Process calc).Id;
Get-UIAWindow -InputObject (Get-Process calc);
# -Recurse = $true
Get-UIAWindow -pn calc -Name *about*; # one window
Get-UIAWindow -pn calc -Name *calc*; # two windows
# earlier, we needed to issue somethink like:
Get-UIAWindow -pn calc | Get-UIAChildWindow -Name *about*; # one window
  • the Set-UIA[ControlType]ToggleState cmdlet
Set-UIACheckBoxToggleState $true;
Set-UIACheckBoxToggleState $false;
  • the Wait-UIAWindow cmdlet. This cmdlet works exactly as the Get-UIAWindow cmdlet (in fact, inherits from) with the only difference: the Wait- cmdlet returns $true/$false instead of AutomationElement/Exception
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem help | Invoke-UIAMenuItemExpand | Get-UIAMenuItem -n *about* | Invoke-UIAMenuItemClick;
Start-Process calc -PassThru;

# by process name
# $true
Wait-UIAWindow -pn calc;
# $true
Wait-UIAWindow -pn calc -n *about*;
# $true
Wait-UIAWindow -pn calc -c *32770*;
# $true
Wait-UIAWindow -pn calc -c *frame*;
# $false
Wait-UIAWindow -pn calc -c *aaa*;

# by process object
# $true
Wait-UIAWindow -InputObject (Get-Process calc);

# by process Id
# $true
Wait-UIAWindow -pid (Get-Process calc).Id;
# $true
Wait-UIAWindow -pid (Get-Process calc).Id -n *calc*;
# $true
Wait-UIAWindow -pid (Get-Process calc).Id -n *about*;
# $false
Wait-UIAWindow -pid (Get-Process calc).Id -n *asdf*;

# by window title (name)
# $false (there is no recursive sarch by default)
Wait-UIAWindow -n *about*
  • the Get-UIAWindow cmdlet (and the Wait-UIAWindow cmdlet as well) supports -AutomationId and -Class parameters in recurse search:
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem help | Invoke-UIAMenuItemExpand | Get-UIAMenuItem -n *about* | Invoke-UIAMenuItemClick;

# the good old way to get a window by process name
Get-UIAWindow -pn calc;

# all windows the process exposes
Get-UIAWindow -pn calc -Recurse;

# the About Calculator window
Get-UIAWindow -pn calc -Name *about*;

# both windows, "Calculator" and "AboutCalculator"
Get-UIAWindow -pn calc -Name *calc*;

# the main window (ClassName -eq 'CalcFrame')
Get-UIAWindow -pn calc -Class *frame*;

# the About window (ClassName -eq '#32770')
Get-UIAWindow -pn calc -Class *327* | Read-UIAControlClass;
Get-UIAWindow -pn calc -Class "#32770";
  • the Get-UIAWindow and Wait-UIAWindow cmdlets now support search for a window or windows only if a certain control or control are on it/them.
It's especially useful (along with other ways to use this) for testing of wizards. For example, a typical setup. After you pressed the Install button, it shows one or more pages. You need to catch the last page, "Complete", for example.
If you use the folllowing code, you'll get an error:
Get-UIAWindow -n *wizard*title* -Seconds 120 | Wait-UIAControlState -SearchCriteria @{controlType="text";name="*complete*"} -Seconds 300;
By the time the last page appeared, you window is gone (every page is a window with its own handle).
Now, the window will be returned only after a control of interest is gotten:
Get-UIAWindow -n *wizard*title* -WithControl @{controlType="text";name="*complete*"} -Seconds 480;
Another sample is the following (we perform it with hands):
# start calc.exe and ensure that it's in the Standard mode
# run code:
Get-UIAWindow -pn calc -Seconds 60 -WithControl @{controltype="button";name="clear*all*"}
# change mode to Statistics: menu item View -> Statistics
# the Get-UIAWindow cmdlet immediately returns the window. The CAD button is the button that has name "Clear all..."

Changed:

  • the Invoke-UIA[ControlType]Toggle cmdlets are now obsolete

Bug fix:

  • Invoke-UIAControlContextMenu on Windows 8 (added WM_MOUSEMOVE after MOUSEDOWN and before MOUSEUP)
  • right click and double click (the same fix)
Now, this works well:
# serivces.msc, run powershell as administrator
# open the Connect... window via right click on the tree item
Get-UIAWindow -n services | Get-UIATreeItem | Invoke-UIAControlContextMenu | Get-UIAMenuItem -n connect* | Invoke-UIAMenuItemClick;
Get-UIAWindow -pn mmc -n *select*computer* | Get-UIAButton Cancel | Invoke-UIAButtonClick;
# double click on a service in the grid:
Get-UIAWindow -n services | Get-UIADataGrid | Get-UIADataItem BranchCache | Invoke-UIAControlClick -DoubleClick;