Skip to content
install

diagnostic · one of 39 Pro saves the page object

Selector health

Which of these locators will survive the next refactor?

A brittle locator works perfectly until the markup moves, which is why flaky suites are usually discovered months after the decision that caused them. This walks every interactive element on the page, works out the best selector available for each, and scores it - a test id at the top, a path through the tree at the bottom - with the attribute worth adding named on the row.

Reach it Press + K on any tab and type selector health. Ctrl + K on Windows and Linux

Which of these locators survives the next refactor, and which does not
reads every interactive element
scores test id 100, a positional path 12
brittle under 40
advises the attribute worth adding
sends nothing
page object pro
section#about

What this actually is

Before writing a suite against a page somebody else built, and during a refactor that is about to move markup around. It measures durability rather than correctness: a three-deep path is a perfectly working locator today and a broken one after the next insertion.

section#reference

What a selector is built out of

test id
survives a rewrite of everything around it
id
stable unless the id is generated per render
label
breaks when the label copy changes
role and name
the name is copy, so a wording change breaks it
text
breaks on a rewrite or a translation
class
breaks the moment styling is refactored or utilities are generated
tag
unique today by accident, not by intent
position
the next element inserted above it breaks this
section#asked

Asked about this diagnostic

Which frameworks does the page object come out in?

Playwright, Cypress, Puppeteer, WebdriverIO and Testing Library. The locator is decomposed once and each dialect writes it in its own idiom, so the output is what you would have typed rather than a Playwright string wrapped in something else.

Is a low score a bug?

No, and that distinction is the whole reading. Every locator on the list works right now against the page in front of you. The score says how long it is likely to keep working, which is a different question and the one a test suite actually depends on.

What about a page with hundreds of controls?

It is sampled rather than walked whole above a cap, and the screen says which it did. A mean over a sample is still the number you want; a walk that takes a minute on a large application is not.

how to use selector health

  1. Open Selector health. Every interactive element on the page is walked and scored.
  2. Read the mean first, then switch to Brittle - the rows under forty are the list to act on.
  3. Take the advice on a bad row: it names the attribute that would move it to the top of the scale.
  4. Generate the page object in your framework once the page scores well enough to be worth one.