Selector

Forge

The expression that identifies an element on a page, and the thing that breaks when the page is redesigned.

What is a selector?

A selector is the expression that identifies a particular element on a page or a screen. It may reference an identifier placed there deliberately or a label visible to the user. Whatever it references, including a bare position in the document structure, becomes a dependency on the page as it is currently written.

Why a selector is a dependency on somebody else's markup

The cost of a selector is paid on a Tuesday morning after a weekend release nobody told the automation team about. A selector anchored to a generated class name describes how the page was assembled rather than what the element is, so a cosmetic change to the layout stops the work. This is the commonest cause of a failed automation, by a wide margin. Choosing what to anchor on is therefore an engineering decision with a maintenance bill attached.

  • A selector anchored to layout breaks on a change with no functional effect.
  • Stability varies enormously between the attributes available on one element.
  • A broken selector often acts on the wrong element rather than failing outright.
  • Vendor applications offer no guarantee that any attribute will persist.

How a selector works

  • The element is examined for a stable identifier placed there deliberately.
  • Where none exists the preference is an accessible label over a structural position.
  • Fragile anchors such as generated class names are avoided entirely.
  • The selector is written with a fallback expression for the same element.
  • A resolution check confirms exactly one element matches before any action.
  • Selectors are held in one place so an application release updates them together.

How a selector is evaluated

A selector is judged across application releases rather than on the day it was written. Examine the following for each automated application:

  • selector failures per application release
  • proportion of selectors anchored to a stable identifier
  • cases where a selector resolved to the wrong element
  • engineering time per release to restore selectors
  • share of selectors with a working fallback

Limitations, risks and common failure modes

  • A selector copied from browser developer tools encodes the entire document path.
  • An element matched by index moves when a column is added above it.
  • A selector resolves to two elements and the action lands on the first.
  • Test environments differ from production in the attributes they render.
  • Nobody discovers a broken selector until a reconciliation finds the missing work.

All 315 terms