This type of search is also a native Automation query.

The most traditional in PowerShell way is to pipeline a window to a Get-UIA[ControlType] cmdlet:
Get-UIAWindow -pn calc | Get-UIAButton -n 1
Internally, every search by default is based on TreeScope.Descendants. For us, this means that we can (and sometimes must) use a series of searches. It's usually necessary in case a window has more than one child window (to flow search into the child window that we need)
Get-UIAWindow -pn $processName | Get-UIAChildWindow | Get-UIAButton -Name OK
or to refine search in case we are performing search by name and this name is not unique:
Get-UIAWindows -pn $processName | Get-UIATree | Get-UIATreeItem -Name $treeItemName;
Get-UIAWindow -pn $processName | Get-UIATabItem -Name 'Select computers' | Get-UIADataGrid | Get-UIADataItem -Name $hostname;

The following parameters are available:
  • -Name (it's usually the visible label or the Name property as it's seen in SharpDevelop)
  • -AutomationId (this could be the name of control given in SharpDevelop or an auto-generated value)
  • -Class (this is often an autogenerated value. Could vary from an operating system to another)
  • -Value (this is typically what we see in text fields, on grid items and similar controls)

This type of search is turned off by default. To turn it on, run the following;
[UIAutomation.Preferences]::DisableExactSearch = $false;
[UIAutomation.Preferences]::DisableWildCardSearch = $true;
[UIAutomation.Preferences]::DisableWin32Search = $true;

Tags: ControlType.Window, ControlType.Button, ControlType.TabItem, ControlType.DataGrid, ControlType.DataItem, child window

Last edited Jan 30, 2013 at 9:31 PM by xinliu, version 3


No comments yet.