Task: demonstrate how to write in text into a text box field.
Requirements: use UI Automation pattern or Win32.
Solution: the typical code is as follows:
Get-UIAWindow -Name $formTitle | ` Get-UIAEdit -AutomationId UsernameBox | ` Set-UIAEditText -Text "text";
Despite the name, the Set-UIAEditText cmdlet uses ValuePattern. This is because that Set-UIAEditText as well as any Set-UIA[ControlType]Text cmdlet is an alias of the Invoke-UIAValuePatternSet cmdlet.
the same story with the Set-UIATextBoxText cmdlet, which is the alias for Set-UIAEditText.
Not every time controls that are supposed to support ValuePattern really support it. This may depend on the developer’s code or on a control’s state. For example, a combo box supports ValuePattern if it has a field to write text in.
As promised, accessing such controls programmatically should raise the ModifiedChanged event.
Sometimes, the ValuePattern can be inaccessible. Due to many reasons, it happens, though rarely. Under these circumstances, you may use the Set-UIAControlText cmdlet, the pure Win32 text setter.
Get-UIAWindow -Name $formTitle | ` Get-UIAEdit -AutomationId UsernameBox | ` Set-UIAControlText -Text "text";
Notice, however, that it works slightly differently: it puts text before the text that is already in the text field. What means that you need first to clean it up, the control, before putting a new text in.