(MS) UIAutomation: navigating through a TreeView


Task: open the Registry editor, navigate to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion and select three values including Default.

Task #2: provide a field for learning the module.

Requirements: just do it. Go through the Registry tree. When the node you are searching for is found, step on it and work with values at the right.

Solution: run the following code:

Get-UIAWindow -Name 'Registry Editor' | `
	Get-UIATreeItem -Name HKEY_LOCAL_MACHINE | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name SOFTWARE | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name Microsoft | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name Windows | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name CurrentVersion | `
	Set-UIAFocus;

	Get-UIADataGrid | `
		Invoke-UIADataItemSelectItem -ItemName `
			DevicePath,MediaPath,'(Default)',SM_GamesName

Note: usually a tree node does not support a click. Click may be used in specific nodes like those having a check box, for example. In this code we activated the CurrentVersion node by setting the focus on it.

Note: Invoke-UIADataItemSelectItem is a typical pattern cmdlet. They are often called Invoke- (MS guidelines say that synchronous operation must be invoked, whilst asynchronous should be verbed as Start-), though they are also may be members of Get- and Set- groups.
To form names for cmdlets is not an easy task! The same problem with the noun part: my rules tell me that the type of control in the name is on the top of usability. As well as the name of pattern.
On the other hand, how it is possible to concatenate such a construct:
Invoke-UIADataItemSelectionItem ?
Therefore, SelectionItemPattern is represented as SelectItem cmdlet. Understandable? I hope.

Patterns that are called Get- and Set- are usually paired.
Get-UIATextBoxText
Set-UIATextBoxText
Which alternatives can be proposed here? Invoke-UIATextBoxTextGet and Invoke-UIATextBoxTextSet? This was my first decision. 🙂

Homework: navigate to a node you like and work with the grid at right.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: