Web Automation Without APIs - Why Accessibility Trees Beat DOM Selectors

Fazm Team··2 min read

Web Automation Without APIs - Why Accessibility Trees Beat DOM Selectors

Most web automation breaks within weeks. The site updates, a CSS class changes, a div gets nested one level deeper, and your carefully crafted selector returns nothing. This is the fundamental fragility of DOM-based automation.

The DOM Selector Problem

DOM selectors target implementation details. div.container > ul.nav-list > li:nth-child(3) > a describes how the page is built, not what the element does. When developers refactor their HTML - which happens constantly - selectors break silently or worse, match the wrong element.

XPath is slightly more resilient but has the same core problem. You are coupling your automation to the site's internal structure.

The Accessibility Tree Alternative

The accessibility tree represents what elements are, not how they are built. A button is a button regardless of whether it is a <button>, a <div role="button">, or a custom web component. A navigation link is identified by its label and role, not its position in the DOM hierarchy.

This makes accessibility-based selectors inherently more stable. When a site redesigns, the visual elements usually keep the same semantic roles and labels. The "Submit" button is still a button labeled "Submit" even if the HTML structure around it changes completely.

Practical Differences

With DOM selectors, a site redesign means rewriting your automation. With accessibility trees, the same automation often survives redesigns untouched - because the semantic structure rarely changes even when the visual layout does.

At Fazm, we use macOS accessibility APIs to interact with desktop applications. The same principle applies - targeting semantic elements rather than pixel positions or UI hierarchy paths gives us automations that survive app updates.

When You Still Need APIs

Accessibility trees are not a replacement for proper APIs when they exist. If a service offers an API, use it. Accessibility-based automation fills the gap for the many services and applications that do not expose programmatic interfaces - which is most of them.

The accessibility tree is the most underused tool in the automation toolkit. It gives you the stability of an API with the flexibility of browser automation.

Fazm is an open source macOS AI agent. Open source on GitHub.

More on This Topic

Related Posts