As you could notice, versions 0.8.3, 0.8.4 and 0.8.5 of the UIAutomation module took a few steps to be simpler and more friendly to the user. We carried out the following improvements to the module:
- added a Win32 click to the InvokePattern cmdlets (i.e., Invoke-UIAButtonClick, Invoke-UIAMenuItemClick, etc) in the case when pattern failed
- added the -Value parameter to Get-UIA[ControlType] cmdlets (i.e., Get-UIAEdit, etc)
- added the parameterless search like Get-UIAButton Next
- and we are working on an improvement to Set-UIAControlText and Set-UIAControlKeys cmdlets
Today’s post sheds light on the brand-new -Value parameter. Many controls support ValuePattern. The preceding link and this one give us the following definitions: “Represents a control that has an intrinsic value that does not span a range and can be represented as a string. This string may or may not be editable depending on the control and its settings.” “Allows clients to get or set a value on controls that do not support a range of values. For example, a date time picker.”
In practice, ValuePattern’s value is a string in a text field. Typically, it’s not wise to search for a text box by the value that is inside. It may be useful in certain situations (i.e., text boxes that are hard to recognize, for example, those that have auto-generated ids in AutomationId. And, in such situations, search for a control by a value in the field could help).
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name  | Invoke-UIAButtonClick; Get-UIAText -Value 123;
A better example is Computer Management -> Disk Management: while names of drives’ squares say the number of device and partition, values contain descriptive information:
Get-UIAWindow -Name *comp*manag* | Get-UIACustom -Value *unallocated*;
Where else the -Value parameter can be used? Accordingly to the suggested controls to patterns mapping, ValuePattern is useful when automating links.
For example, a link in an event’s help page in Event viewer:
Get-UIAWindow -n *event*event* | Get-UIAHyperlink -Value *event*log*online*;
What’s more, link’s href is available even it’s invisible:
Get-UIAWindow -n *control*pattern*mapping* | Get-UIAHyperlink -Value '*#control_mapping_clients*' | Read-UIAControlName;
Finally, the best area of applicability of the -Value parameter is grids and other complex controls.