Walk the automation tree to find a button: $button = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, (New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Button)))
Invoke the button using the InvokePattern: $invokePattern = $button.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern); $invokePattern.Invoke()
Read a text field with ValuePattern: $valuePattern = $field.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern); $valuePattern.SetValue('hello')
Known gotchas
UI Automation tree walking is slow on complex windows; use CacheRequest to batch-fetch multiple properties in a single round-trip for performance-sensitive scripts
Many Win32 and WPF controls expose different patterns (InvokePattern, TogglePattern, SelectionPattern); check the control type first and request the correct pattern or GetCurrentPattern will throw
Applications that render their UI on a DirectX canvas (games, Electron apps without accessibility hooks) expose little or no automation tree — UI Automation cannot interact with them
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp