An index selector does not break when a page changes. It keeps working, and presses a different button.
In the test page I built for this, button index=1 pressed Reset in one layout and Delete in the other. Same script, same page, one query string apart. The delete click was stopped by a guard — but the script had decided to press it, and nothing in the script knew it was wrong.
I built a small runner around the Chrome DevTools team's MCP server and measured this instead of arguing about it: 16 scenario runs, a session-injection set, a retry set, and a mutation test that puts the layout back to front on purpose. This post is the measurement, the parts I got wrong first, and what I would hand to a client.
What I built
A CLI that executes an admin-page job from a JSON scenario file and leaves behind a result, evidence, and a failure code.
-
Engine:
chrome-devtools-mcp1.14.0 (Apache-2.0), a separate process speaking stdio JSON-RPC, 33 tools. Not vendored; installed withnpm. -
Runner: Python standard library only. No
pip install, no Playwright dependency in my code. -
Tests: 58 unit tests (
pytest), covering the snapshot parser, the guard, extraction, the runner, session handling, retry, and reuse. -
Outputs per run:
result.json(step timings, MCP call counts, extracted rows, assertions, failure class, environment),report.md, a CSV with a UTF-8 BOM, and PNG screenshots with a SHA-256 for each.
The engine is not the interesting part. The job layer is: how you point at an element, how you decide whether the result is right, how you prove what happened, and how you name the failure.
The experiment: role + name vs index
The demo site serves the same admin page in two layouts. It is modelled on a Korean order desk, so the button labels in the repository are Korean; this post uses their English equivalents throughout — Search, Reset, Delete — and every number below was measured on that same page.
-
layout=std: search form above the table, buttons in the order Search, Reset. -
layout=alt: table above the form, button order reversed.
Two strategies, same goal (press Search once, then read the table):
| Strategy | std | alt | Passed |
|---|---|---|---|
button "Search" — role + accessible name |
opened 1 row | opened 1 row | 2/2 |
button index=1 — the second button in the list, 0-based |
pressed Reset | pressed Delete | 0/2 |
I re-ran the mutation test while writing this and got the same split, with the same two wrong buttons:
name / std ok clicked button "Search" 1 data row
index / std failed clicked button "Reset" timeout
name / alt ok clicked button "Search" 1 data row
index / alt failed clicked button "Delete" policy_blocked
Read the index rows again. In std it did not crash: it reset the form and then waited for a table that was no longer filtered, so the run ended in timeout — a code that sends you looking at wait settings for a problem that is not about waiting. In alt it tried to delete. A destructive-action guard refuses any click whose label contains delete/pay/refund terms unless the scenario sets confirmed: true and the runner is started with --allow-destructive. So the run ended in policy_blocked with nothing lost, and with a screenshot of the button it tried to press.
That guard is the reason this post is a measurement and not a postmortem. Positional targeting fails by choosing a plausible neighbour, and "plausible neighbour" is how automation deletes records.
Three more traps in the demo push the same point, because a demo that only tests the happy path proves nothing:
- The first Search button in the list is a
display:noneduplicate, so counting buttons is off by one before you start. - Rows are reshuffled on every request, so
nth-childselectors do not reproduce. - A banner is inserted late, shifting the DOM.
None of these are exotic. They are what a CMS upgrade does to a page over a weekend.
The accessibility tree is for clicking, not for reading tables
The other thing I assumed wrong: that the snapshot would give me the table.
take_snapshot exposes buttons, inputs, comboboxes and their accessible names, and that is what targeting should use. But on both of my pages it returned no table/row/cell roles — the cell text arrived as a flat list of strings. Parsing rows back out of a flattened text stream is guesswork with extra steps.
So the split is explicit:
-
Interact: resolve targets in the accessibility tree by role + name (plus
exactorregexwhen the name is noisy). -
Read data:
evaluate_scriptagainst the DOM, scoped to a selector, and return rows.
{"action": "extract_table", "selector": "#orders", "name": "orders"},
{"action": "assert", "kind": "rows_eq", "name": "orders", "value": 1},
{"action": "assert", "kind": "field_all_eq", "table": "orders", "field": "status", "value": "shipped"}
Two tables on the report page came out at 5 rows each (header + 4), and the order table at 2 rows (header + 1). The assertions matter as much as the extraction: a read that returns zero rows, or the wrong number of them, has to fail loudly. Silent empty CSVs are how people stop trusting an automation.
Waits are a setting, not a bug
One demo page renders its result 2.5 seconds after the click.
- Timeout budget 700 ms →
timeout. - Same scenario, same code, budget 8000 ms → success in 3,201 ms.
The useful part is not that a longer wait works. It is that the report says which step had which budget, so "the page got slower" and "my selector is wrong" stop looking identical. A missed wait and a renamed button end the same way on a screenshot — a run that did not finish — but they carry different codes and different next actions.
Sessions: 5 of 5, including the failure cases
A logged-in admin page is where most automation projects quietly stop. I measured five cases against a demo page that requires a session cookie:
| Case | Session source | Result | Runner | Code |
|---|---|---|---|---|
| no session | — | blocked | 683 ms | login_required |
| cookie JSON | --session-file |
opened, extracted, asserted | 2,487 ms | — |
| expired token | --session-file |
blocked | 1,003 ms | login_required |
| profile, seeded | --session-profile |
logged in with credentials | 2,052 ms | — |
| profile, reused | --session-profile |
opened without credentials | 2,484 ms | — |
All five behaved as designed: three opened the page, two were stopped and labelled. The last row is the one worth keeping: a new process opened the protected page using only a Chrome profile directory, with no password in the environment. That is the shape a client actually wants — one manual login, then unattended runs until the session expires.
The limit is real and easy to state: a page script cannot set an HttpOnly cookie. So a cookie-file injection silently misses exactly the cookie that matters for many admin sessions. The runner records it as skipped: http_only and reports which cookie names it saw — in my run, two cookies, one of them HttpOnly and therefore out of reach for a page script. You find that out on the first run instead of the fifth.
Secret handling, since this is the part that gets a proof of concept rejected in review:
- Credentials come from an environment JSON (
WEBOPS_VARS) or--var, never from the scenario file. - Session files inside the repository are refused (
session_in_repo). - After injection the runner reads
document.cookieback and verifies; a mismatch issession_injection_failed, not a silent continue. - Logs and result JSON carry cookie names and counts only.
- File permissions looser than 600 raise a warning.
The one-second fixed cost
Every run pays for starting the browser server: spawn 7–12 ms, initialize about 1.0–1.4 seconds, tools/list 12–17 ms. On a 2-second job that is roughly 40% of the wall time.
Reusing one server process across scenarios removes it:
| Mode | Wall time, 3 scenarios | Startup paid |
|---|---|---|
| cold, new process per scenario | 10.1 s | 1,195 / 1,075 / 969 ms |
| warm, one process reused | 7.1 s | 1,117 ms once, then 0 |
That is 0.996 s saved per scenario (2.988 s per round of three, average of two rounds). For a daily three-scenario job this is a rounding error. For a CI job that runs fifty checks, or a batch sweep across layouts, it is most of the build.
Two honesty notes about this number. First, the runner's own total_ms starts after the server is up, so the fixed cost is invisible there; the comparison has to be CLI wall time. Second, the figures move. When I re-ran one scenario later the same evening it took 4,129 ms with initialize measured at 2.29 s on a loaded box, against ~1 s in the run above. Treat ±10% as normal and a doubled startup as possible.
Retry only what a retry can fix
Two runs of the same flaky page:
- No retry:
timeoutafter 2,735 ms. -
--retry 2: first attempttimeoutat 2,630 ms, second attempt ok in 553 ms.
The value is in what the retry refuses to do. assertion_failed, element_not_found and policy_blocked stop immediately, because running them again produces the same result and hides the real problem. Transient codes (timeout, tool_error, http_error, session injection failure) get exponential backoff. Before a retry the runner closes dialogs and switches to a fresh tab, so the second attempt does not inherit the first attempt's half-finished state.
The taxonomy is the deliverable
"We can fix it" is not a maintenance contract. This is:
| Code | Meaning | What actually produced it |
|---|---|---|
element_not_found |
structure or label changed | a public test page labelled the field Customer name: with a colon, so exact matching failed |
timeout |
wait budget or slow load | result element after 2.5 s against a 700 ms budget |
login_required |
no session, or session rejected | redirect to /login?next=/admin/protected
|
assertion_failed |
data does not match the rule | 12 rows where the rule said 1 |
policy_blocked |
guard stopped it | a click on an element whose label contains delete/pay |
http_error / tool_error
|
4xx/5xx, browser or tool failure | direct HTTP check outside the browser |
session_* |
session preparation failed | session file inside the repo; cookie that did not stick |
Seven classes, each with a different fix and a different owner: page change (client), wait budget (config), credentials (ops), data rule (business), safety (by design).
What this does not tell you
- These are single-run numbers on a Linux 2 vCPU box (no GPU),
chrome-headless-shell159, viewport 1280×720. They are not a benchmark. - The targets are pages I wrote, plus one public HTTP test service. A real admin page will need its own measurement, and some will need a seat, a VPN, or a person.
- Captchas, second factors and SSO are out of scope. A profile login covers "log in once by hand"; it does not defeat a bot check, and I would not want it to.
- Icon-only buttons with no accessible name cannot be targeted by name. The cheapest fix is on the page: add
aria-label. - Extraction reads
innerText, so columns hidden on screen do not appear in the CSV. - Headless rendering differs slightly from a real screen (fonts, scroll positions), which matters when a screenshot is the evidence.
Run it
npm i chrome-devtools-mcp@1.14.0
python3 -m pytest tests -q # 58 passed
python3 demosite/serve.py --port 8811 # separate terminal
python3 -m webops run recipes/admin_order_lookup.json \
--base-url http://127.0.0.1:8811 --out runs/order
python3 scripts/mutation_test.py # role+name vs index
The demo site is deliberately hostile: hidden duplicate button, reshuffled rows, late banner, reversed layout, destructive button, login wall, slow page, flaky endpoint. It is there so the failure classes can be reproduced on purpose instead of discovered in production.
The code, the scenario files, the demo site, the tests and the raw run folders are here:
https://github.com/Gros19/aiget-webops-mcp
If you want the written version of the adjacent problem — how a retrieval layer returns a stale revision with total confidence, measured on 60 chunks — the English starter sample is free here:
https://aiget.gumroad.com/l/rag-brag-english-starter
If you maintain an admin-page script, the first number worth having is how many of its clicks are positional. Count them before the redesign finds them.
Top comments (0)