Tag Archives: TreeScope.Ancestors

Daily automation: dumping control’s genealogy


This is a new edition of the old post.

Note: this post is deprecated, please refer to my comment below.

One more way to find out where in the Automation tree a control resides is to use the Get-UIAControlAncestors cmdlet. We are told that TreeScope.Parent and TreeScope.Ancestors used as filter for search will call the functionality that is not yet implemented? However, the cmdlet does perform the search from the very bottom of the hierarchy to the topmost window. Let’s take Calculator and dump the control hierarchy:

Task: demonstrate using the search to the top cmdlet.

Requirements: perform search that consumes a part of control’s name and retrieve all the ancestors of the search result.

Solution: the following code prints out all the hierarchy in reverse order:

Set-StrictMode -Version Latest;

ipmo [path]\UIAutomation.dll;

# here we are searching for all the element whose names start with 'a'

Start-Process calc -PassThru | Get-UIAWindow | Search-UIAControl -Name A* | `

%{Write-Host "===========================================================";

Write-Host "@{Name='$($_.Current.Name)';
AutomaitonId='$($_.Current.AutomaitonId);
ControlType='$($_.Current.ControlType.ProgrammaticName)'}";
$_ | Get-UIAControlAncestors | `

%{Write-Host "@{Name='$($_.Current.Name)';
AutomaitonId='$($_.Current.AutomaitonId);
ControlType='$($_.Current.ControlType.ProgrammaticName)'}";}};
Advertisements

Daily automation: dumping control’s genealogy


Note: this post is deprecated, please refer to my comment below and the last edition of this post.

One more way to find out where in the Automation tree a control resides is to use the Get-UIAControlAncestors cmdlet. We are told that TreeScope.Parent and TreeScope.Ancestors used as filter for search will call the functionality that is not yet implemented? However, the cmdlet does perform the search from the very bottom of the hierarchy to the topmost window. Let’s take Calculator and dump the control hierarchy:

Task: demonstrate using the search to the top cmdlet.

Requirements: perform search that consumes a part of control’s name and retrieve all the ancestors of the search result.

Solution: the following code prints out all the hierarchy in reverse order:

Set-StrictMode -Version Latest;
ipmo [path]\UIAutomation.dll;
# here we are searching for all the element whose names start with 'a'
Start-Process calc -PassThru | Get-UIAWindow | Search-UIAControl -Name A* | `
 %{Write-Host "===========================================================";
 Write-Host "@{Name='$($_.Current.Name)'; AutomaitonId='$($_.Current.AutomaitonId); ControlType='$($_.Current.ControlType.ProgrammaticName)'}"; $_ | Get-UIAControlAncestors | `
 %{Write-Host "@{Name='$($_.Current.Name)'; AutomaitonId='$($_.Current.AutomaitonId); ControlType='$($_.Current.ControlType.ProgrammaticName)'}";}};
%d bloggers like this: