Get-ControlFirstChild and ControlType

Dec 11, 2013 at 3:05 AM
The documentation seems to indicate that you can specify a ControlType. However it doesn't seem to work. For example:

Get-UIAControlChildren -ControlType Text #works and returns a list of Text elements
Get-UIAControlFirstChild -ControlType Text #fails to load the first from the above list Appears to load the first child ignoring the filtering

Am I missing something?

Verbose is below. Shows it doesn't pick up the filter properly:
VERBOSE: Get-UIAControlFirstChild: ControlType = System.String[]
VERBOSE: Get-UIAControlFirstChild: Class =
VERBOSE: Get-UIAControlFirstChild: Name =
VERBOSE: Get-UIAControlFirstChild: AutomationId =
VERBOSE: Get-UIAControlFirstChild: [checking the control] the input control is of the ControlType.Custom type
VERBOSE: Get-UIAControlFirstChild: outputting the object
VERBOSE: Get-UIAControlFirstChild: the output object is not null
VERBOSE: Get-UIAControlFirstChild: is going to run scriptblocks
VERBOSE: Get-UIAControlFirstChild: cmdlet is of the HasScriptBlockCmdletBase type
VERBOSE: Get-UIAControlFirstChild: run OnSuccess script blocks
VERBOSE: Get-UIAControlFirstChild: preparing scriptblocks
VERBOSE: Get-UIAControlFirstChild: scriptblocks were prepared
VERBOSE: Get-UIAControlFirstChild: running scriptblocks
VERBOSE: Get-UIAControlFirstChild: Scriptblocks finished successfully
VERBOSE: Get-UIAControlFirstChild: WriteObjectMethod045OnSuccessScreenshot UIAutomation
VERBOSE: Get-UIAControlFirstChild: cmdlet as HasTimeoutCmdletBase
VERBOSE: Get-UIAControlFirstChild: (CurrentData.CurrentWindow != null && CurrentData.LastResult != null) || (outputObject as AutomationElement) != null
VERBOSE: Get-UIAControlFirstChild: sleeping if sleep time is provided
VERBOSE: Get-UIAControlFirstChild: outputting the result object
VERBOSE: Get-UIAControlFirstChild: getting the element again to ensure that it still exists
VERBOSE: Get-UIAControlFirstChild: System.Windows.Automation.AutomationElement
VERBOSE: Get-UIAControlFirstChild: returning the object
Coordinator
Dec 11, 2013 at 7:38 AM
Edited Dec 11, 2013 at 7:41 AM
Hi TBlackbird,
this is a bug.
All three lines do the same:
Start-Process calc -PassThru | Get-UiaWindow | Get-UiaButton 1 | Get-UiaControlParent | Get-UiaControlFirstChild
Start-Process calc -PassThru | Get-UiaWindow | Get-UiaButton 1 | Get-UiaControlParent | Get-UiaControlFirstChild -ControlType Button
Start-Process calc -PassThru | Get-UiaWindow | Get-UiaButton 1 | Get-UiaControlParent | Get-UiaControlFirstChild -ControlType Text
Coordinator
Dec 11, 2013 at 9:41 AM
Yep, the TreeWalker, the thing we use here, does not support filtering by ControlType. It's just a parameter that inherited from above, namely the class from Get-Uia[ControlType] cmdlets grow.
The parameter will be removed since 0.8.7 alpha 2 (the nearest version), thank you, TBlackbird.

If you need to get a child of a certain type, use the Get-UiaControlChildren cmdlet with the -ControlType parameter, and, starting from an item of the result, you could navigate on this level via Get-UiaControlPreviousSibling and Get-UiaControlNextSibling cmdlets.