Walk a legacy Win32 application's UI Automation tree with TreeWalker to locate controls that lack stable AutomationIds
domain: learn.microsoft.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Create a TreeWalker with a Condition (e.g. combining IsControlElement and IsEnabled via AndCondition) to skip irrelevant raw elements during traversal
Choose from the three predefined walkers — RawViewWalker, ControlViewWalker, ContentViewWalker — typically ControlViewWalker for navigating interactive UI, since it filters out non-control elements
Traverse with GetFirstChild/GetNextSibling/GetParent starting from a known anchor element such as the target window, never from the root desktop element, since walking the full desktop tree can be extremely slow or overflow
Combine tree walking with property-based fallback matching (ClassName, ControlType, Name substring) since legacy Win32/MFC/WinForms apps often lack meaningful AutomationId values
Re-walk from the anchor after any UI state change rather than holding long-lived element references, since cached elements can go stale when the underlying control is recreated
Known gotchas
Never pass the root desktop element into a TreeWalker traversal without narrow conditions — mapping the entire desktop tree can hang or stack-overflow the client
Elements that don't match the TreeWalker's condition are skipped entirely, not returned as unmatched nodes, so an overly strict condition can make real controls invisible to the walk
Cached AutomationElement references can become stale after the underlying window redraws or recreates controls, throwing an element-not-available error on the next call
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?