Skip to content

Selectors

A selector is how you tell the bot which element to act on: this button, that field, that cell. It’s the most important concept in browser (Browser) and desktop (Desktop) automation: without a good selector, the activity doesn’t know where to click or what to read, and the bot fails.

The good news is that you rarely ever write a selector by hand: you capture it by pointing the mouse with UI Discover. This page explains what a selector is and how it’s made, so you understand what you’re capturing, know how to adjust it when a page changes, and build selectors that don’t break over time.

A web page or window does not have “fixed coordinates”: a button changes position if the window is enlarged, if a notice appears above it, or if the app is updated. Pointing by coordinates (click on pixel 320,540) is fragile: the first time something moves, the bot clicks in the wrong place.

A selector, on the other hand, identifies the element by what it is, not by where it is: “the button whose text is Save”, “the field whose id is usuario”. This way the bot finds it even if it has moved.

A selector is a hierarchy of nodes, from the window or browser (the root) to the specific element you want to interact with (the sheet). Each node is a level of that hierarchy and has a type and attributes.

Node typeRepresentsAttribute examples
wndA window of the operating system (the app, the browser)app, title, cls
webctrlA web part (within the browser)tag, id, aaname, name, type, idx
frameAn iframe (page embedded within another)src, name, idx
ctrlA native desktop control (button, field, list…)controlType, automationId, name, idx

In the UI Discover editor you see those nodes as cards: the last one (the • elemento) is the target, and the previous ones (• contexto) are its ancestors, which help locate it without ambiguity.

A selector also stores two auxiliary data that are automatically captured and serve as a safety net (we explain them in How to find the item):

  • Backing CSS — a CSS selector for the element.
  • XPath — the absolute path of the element in the document.

An attribute is a clue to identify the element. You don’t need all of them: the fewer and more stable, the better. These are what a selector can use:

AtributoSignificadoContexto
appWindow Executable (chrome.exe, notepad.exe)window
titleWindow or page titlewindow
clsCSS (web) class or Win32 window classambos
tagEtiqueta HTML (BUTTON, INPUT, TABLE, TR, TD…)web
idHTML element id attribute — most stableweb
aanameAccessible name: the visible text or aria-label of the elementweb
nameAtributo name del HTML (muy estable en formularios)web
typeAtributo type (submit, text, checkbox…)web
hrefDestination of a linkweb
srcOrigin of a frame or imageweb
idx1-based index between siblings of the same type (tiebreaker)ambos
controlTypeUIA control type (Button, Edit, List…)desktop
automationIdControl AutomationIdmost stable on desktopdesktop
nameNombre accesible del control de desktopdesktop

Here’s the part that makes a selector robust or brittle. The value of any attribute can be written in four ways, and choosing well is what prevents the bot from breaking when the text changes.

ModeHow to writeMatches…Example
LiteralThe text as isExact match (case insensitive)usuario
WildcardWith * at the start, end or bothAny text at the * positionPedido * matches Pedido 1024
ExpressionEmpezando por =Whatever expression returns when executing= "fila-" + indice
RegexBetween bars /patrón/The regular expression pattern/^Order-\d+$/

This is best understood with a real case:

  • An invoice whose title is “Order 1024” today and “Order 1025” tomorrow. If you capture the literal Pedido 1024, the selector works once and fails the next day. Change the value to Pedido * and it will work always.
  • In a loop that loops through rows, the idx attribute can be an expression: = fila + 1. Thus the same activity points to row 1, 2, 3… as the loop progresses. This is what turns a static selector into a dynamic one.

How to find the element (resolution order)

Section titled “How to find the element (resolution order)”

When the activity runs, Zoan Automation tries to locate the element by trying strategies from most stable to most fragile, and sticks with the first one that works. Knowing this order helps you understand why a selector is good or bad — and it’s exactly what the Validate button in UI Discover measures.

In the browser, the order for each node is:

  1. id → the most stable.
  2. data-testid → estable en apps modernas.
  3. name → muy estable en formularios.
  4. aria-label → preciso e independiente del idioma.
  5. placeholder → for unlabeled fields.
  6. aaname (texto / nombre accesible).
  7. CSS del nodo (tag + cls + type).
  8. Backup CSS (the security net captured by targeting).
  9. Absolute XPath → last resort, fragile to structure changes.

On the desktop the logic is parallel, prioritizing automationId and name of control over position.

Anchors: when the element has nothing of its own

Section titled “Anchors: when the element has nothing of its own”

Sometimes the target element has no unique attributes: a field with no id, no name, no label — just a blank box next to the text “Last Name”. How to distinguish it from the other ten empty fields on the screen?

With an anchor: you locate the objective in relation to a reference element that is identifiable. “The field that is to the right of the LastName label.”

RelationshipThe goal is…
right_ofto the right of the anchor
left_ofto the left of the anchor
belowdebajo del ancla
aboveencima del ancla
nearestclosest to anchor (no direction)

Each anchor has a maximum distance (in pixels, 250 by default): if there are no candidates within that radius in the given ratio, the anchor is not applied. You capture and set anchors from UI Discover.

  1. Capture, don’t write. Use UI Discover: point and click. Only adjust by hand what is necessary.
  2. Less is more. Remove attributes that do not provide uniqueness. A single id is enough; adding cls, idx and position only makes it more fragile.
  3. Prioriza lo estable: id / automationId > name / aria-label / aaname > clases > idx / XPath.
  4. Use wildcards for text that changes. Any number, date or folio in a value → convert it to * or regex.
  5. Use anchors, not positions. Before setting idx, look for stable nearby text.
  6. Validate on the actual page. Press Validate and chase the green. Orange and purple are warnings that it will break soon.
  7. Refetch after a redesign. If the target application is updated, refetch the affected selectors; It’s faster than debugging bugs.
  • UI Discover — the tool to capture selectors by pointing the mouse.
  • Browser — activities that use selectors on web pages.
  • Desktop — activities that use selectors in Windows applications.
  • Expressions — to construct dynamic attribute values.