Use the Inspect tool (`inspect.exe`) from the Windows SDK to explore the UIA element tree of any running application — hover over UI elements to see their `AutomationId`, `Name`, `ControlType`, and `LocalizedControlType` properties.
In .NET, add a reference to `System.Windows.Automation` and obtain the root element: `AutomationElement root = AutomationElement.RootElement`, then search with `FindFirst` or `FindAll` using a `PropertyCondition`, e.g., `new PropertyCondition(AutomationElement.AutomationIdProperty, 'btnSubmit')`.
Invoke actions through control patterns: obtain `InvokePattern` with `element.GetCurrentPattern(InvokePattern.Pattern)` then call `pattern.Invoke()` for buttons, or use `ValuePattern` to set text in input fields.
For Python, use the `comtypes` or `pywinauto` library which wraps UIA; for quick scripting, `pywinauto` provides a higher-level API that calls UIA internally.
Handle synchronisation by subscribing to UIA events (e.g., `AutomationFocusChangedEvent`) or by polling with `FindFirst` in a loop with a timeout rather than using arbitrary `Thread.Sleep` calls.
Known gotchas
UIA element trees can be deep and slow to traverse. Searching from `AutomationElement.RootElement` with no scope constraint does a full tree walk across all windows and processes, which can take several seconds. Always narrow the search by first obtaining the target application's top-level window element.
`AutomationId` is set by the application developer and is not guaranteed to be unique or stable across versions. Prefer `AutomationId` when available, but fall back to `Name` + `ControlType` combinations when IDs are absent or duplicated.
Many Electron, WPF WebView2, and CEF-based applications render their UI in an embedded web view that appears as a single opaque UIA element. You cannot reach individual buttons or text fields inside the web view through UIA — use browser automation (CDP or WebDriver) against the embedded renderer instead.
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