Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
95cb7e7
fix(web): check a radio or checkbox through its own label when the la…
samanyudas Oct 24, 2026
c88fd0b
fix(web): skip the label stand-in for disabled fieldsets, hidden labe…
samanyudas Oct 24, 2026
dc700e8
fix(web): choose the label stand-in past loading masks and wait for a…
samanyudas Oct 26, 2026
0c51c84
fix(web): click no control after a cancelled stand-in read, and dispo…
samanyudas Oct 26, 2026
779130e
refactor(web): type the label stand-in as undefined instead of a null…
samanyudas Oct 27, 2026
2e0883d
test(web): give the label refusal cases a 500ms deadline
samanyudas Oct 27, 2026
fc587db
Merge remote-tracking branch 'origin/main' into HEAD
okwasniewski Oct 28, 2026
15e04fa
Merge branch 'main' into fix/web-check-through-label
samanyudas Nov 4, 2026
8dc0761
Merge remote-tracking branch 'origin/main' into fix/web-check-through…
samanyudas Nov 6, 2026
dd7d358
test(web): resolve the element target through ElementList, as an obse…
samanyudas Nov 6, 2026
eb1d933
test(web): cross-check a checkbox or radio its label draws over no box
samanyudas Nov 6, 2026
74cf1b0
fix(web): list a checkbox or radio its own label draws over no box
samanyudas Nov 6, 2026
da8729d
docs(web): say the agent sees a checkbox its label draws over no box
samanyudas Nov 6, 2026
69f87ea
test(web): pin that the observation shows a label-drawn checkbox the …
samanyudas Nov 6, 2026
a249130
refactor(web): read a drawn-by-label control's labels the way the rea…
samanyudas Nov 6, 2026
e05a6f1
docs(web): limit the label-click claims to what the click checks
samanyudas Nov 6, 2026
ae1dfad
Merge remote-tracking branch 'fork/fix/web-check-through-label' into …
samanyudas Nov 6, 2026
6273827
fix(web): list a label-drawn checkbox only under a label a tap can click
samanyudas Nov 6, 2026
a29cc91
fix(web): leave out a label-drawn checkbox whose label holds a link
samanyudas Nov 6, 2026
0dab444
docs(web): say the agent still sees a link inside a label-drawn check…
samanyudas Nov 6, 2026
3b87ad2
Merge branch 'main' into fix/web-check-through-label
samanyudas Nov 7, 2026
e18c9ec
Merge branch 'main' into fix/web-list-boxless-checkbox
samanyudas Nov 7, 2026
ec2c689
test(web): pin the clicked control and cover uncheck through a label
samanyudas Nov 7, 2026
5ca7075
fix(web): leave out a label-drawn checkbox whose label is itself a co…
samanyudas Nov 7, 2026
fe9bd76
Merge remote-tracking branch 'fork/fix/web-check-through-label' into …
samanyudas Nov 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/check-through-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@e2e-dev/web": patch
---

`check`, `uncheck`, and `tap` click a checkbox or radio hidden under its own label (as in Element Plus) through that label. `uncheck` still refuses a native radio without clicking it. Anything else on top of the point the click lands on still fails `ACTION_FAILED`.
5 changes: 5 additions & 0 deletions .changeset/list-label-drawn-checkbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@e2e-dev/web": patch
---

The agent now sees a checkbox or radio that a component library shrinks to no size under its own label (as in Element Plus), with its checked state. Before, it saw only the label text, and a tap that ticked the box reported no change.
4 changes: 4 additions & 0 deletions docs/reference/screen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ check(options?: ActionOptions): Promise<void>;
await screen.getByRole('checkbox', 'Remember me').check();
```

On the web engine, a checkbox or radio hidden under its own label (as in
Element Plus) is clicked through that label. Anything else on top of the
point the click lands on still fails `ACTION_FAILED`.

#### `uncheck`

```ts
Expand Down
7 changes: 7 additions & 0 deletions docs/web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ link is also listed as a control. The agent reads the first 512 characters
of each block of text. In a longer block, e2e also lists its links and
emphasized text on their own.

The agent also sees a checkbox or radio that a component library shrinks
to no size under its own label, as Element Plus does, with its checked
state. A tap on it clicks the label. When that label is or holds a link
or another control, the agent sees the label's text and that control but
not the checkbox, since a click on the label could land on the link. Locators still call that control hidden, as
Playwright does, so check it with `toBeChecked()`, not `toBeVisible()`.

### Scoping a test to one size

`platforms` and `requires` can't select a viewport, because every browser
Expand Down
125 changes: 123 additions & 2 deletions packages/web/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con
retryable: false,
});
}
await element.click({ timeout: remaining() });
await clickControl({ kind: 'element', element }, verb, { timeout: remaining(), signal: operation.signal });
const hint = radio === 'aria' ? '; a radio usually clears only when another radio in its group is selected' : '';
const unchanged = (detail = ''): EngineError =>
new EngineError('NOT_ACTIONABLE', `${verb} clicked the control but its checked state did not change${detail}${hint}`, {
Expand Down Expand Up @@ -91,6 +91,127 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con
}
}

/**
* What the page throws while a checkbox or radio and every one of its labels
* are unrendered, so a click could reach none of them yet.
*/
const UNRENDERED = 'the control and its labels are not visible';

/**
* Runs in the page. A component library (Element Plus) hides a native
* checkbox or radio under its label's styled spans with `z-index: -1`, or
* gives it no box at all, so Playwright refuses the input itself (`<span>
* intercepts pointer events`, `element is not visible`) though a user's click
* there reaches it through the label. Returns that label, or null to click the
* control itself. The choice reads the control and its labels only, past
* anything else on top (a loading mask, a modal): Playwright's checks on the
* label wait that out, or fail on it. Throws `UNRENDERED` while none of them
* is rendered (a dialog not open yet), since nothing tells the two apart then.
*/
function pickStandIn(node: Element, unrendered: string): HTMLLabelElement | null {
if (!(node instanceof HTMLInputElement) || (node.type !== 'checkbox' && node.type !== 'radio') || node.matches(':disabled')) {
return null;
}
const labels = [...(node.labels ?? [])];
const root = node.getRootNode();
if (labels.length === 0 || (!(root instanceof Document) && !(root instanceof ShadowRoot))) return null;
const INTERACTIVE = 'a,button,input,select,textarea,summary,[contenteditable],[role="button"],[role="link"]';
const hasBox = ({ width, height }: DOMRect): boolean => width > 0 && height > 0;
const centre = ({ left, top, width, height }: DOMRect): [number, number] => [left + width / 2, top + height / 2];
const topmost = (x: number, y: number): Element | undefined =>
root.elementsFromPoint(x, y).find((hit) => hit === node || labels.some((label) => label.contains(hit)));
const pressesInteractive = (label: HTMLLabelElement, hit: Element | undefined): boolean =>
label.contains(hit?.closest(INTERACTIVE) ?? null);
node.scrollIntoView({ block: 'nearest', inline: 'nearest' });
const box = node.getBoundingClientRect();
if (!hasBox(box)) {
const shown = labels.filter((label) => hasBox(label.getBoundingClientRect()) && label.checkVisibility({ visibilityProperty: true }));
if (shown.length === 0) throw new Error(unrendered);
return (
shown.find((label) => {
label.scrollIntoView({ block: 'nearest', inline: 'nearest' });
return !pressesInteractive(label, topmost(...centre(label.getBoundingClientRect())));
}) ?? null
);
}
const [x, y] = centre(box);
const hit = topmost(x, y);
if (hit === undefined) throw new Error(unrendered);
const label = labels.find((own) => own.contains(hit));
if (label === undefined || pressesInteractive(label, hit)) return null;
const outer = label.getBoundingClientRect();
return x >= outer.left && x <= outer.right && y >= outer.top && y <= outer.bottom ? label : null;
}

/**
* Runs in the page: where a click on the label lands, the centre of its
* control relative to the label, or none for a control with no box, which
* takes the label's centre.
*/
function controlPoint(label: HTMLLabelElement): { x: number; y: number } | null {
const box = label.control?.getBoundingClientRect();
if (box === undefined || box.width === 0 || box.height === 0) return null;
const outer = label.getBoundingClientRect();
return { x: box.left + box.width / 2 - outer.left, y: box.top + box.height / 2 - outer.top };
}

/**
* Clicks a control with Playwright's actionability checks, through its own
* label when `pickStandIn` names one. The checks then run on the label, so
* anything else on top, such as a modal, still fails NOT_ACTIONABLE. The
* choice is read again until the control or a label renders, within the
* deadline.
*/
async function clickControl(
target: ActionTarget,
verb: 'tap' | 'check' | 'uncheck',
options: { timeout: number; signal: AbortSignal; modifiers?: KeyModifier[] },
): Promise<void> {
const { signal, ...click } = options;
const deadline = new Deadline(options.timeout);
const remaining = (): number => Math.max(1, deadline.remaining());
Comment thread
samanyudas marked this conversation as resolved.
Resolved
let label: ElementHandle<HTMLLabelElement> | undefined;
let firstRead = true;
await pollCondition({
deadline,
signal,
negated: false,
evaluate: async () => {
const first = firstRead;
firstRead = false;
try {
const handle =
target.kind === 'locator'
? await target.locator.evaluateHandle(pickStandIn, UNRENDERED, { timeout: remaining() })
: await target.element.evaluateHandle(pickStandIn, UNRENDERED);
label = handle.asElement() ?? undefined;
if (label === undefined) void handle.dispose().catch(() => undefined);
return true;
} catch (cause) {
if (message(cause).includes(UNRENDERED)) return undefined;
// A read after one that found nothing rendered times out only at the deadline, which ends the poll.
if (!first && isPwTimeout(cause)) return undefined;
throw cause;
}
},
onTimeout: () =>
new EngineError('NOT_ACTIONABLE', `${verb} did not become actionable in time: ${UNRENDERED}`, { retryable: false }),
});
// The operation abandons this call when cancelled; a read still in flight then must not lead to a click.
if (label === undefined) {
signal.throwIfAborted();
await asActionable(target).click({ ...click, timeout: remaining() });
return;
}
try {
const position = await label.evaluate(controlPoint);
signal.throwIfAborted();
await label.click({ ...click, timeout: remaining(), ...(position === null ? {} : { position }) });
} finally {
void label.dispose().catch(() => undefined);
}
}

/**
* Which kind of radio a checkable element is, if any. A native radio can be
* selected but never cleared by a click. An ARIA radio is clicked like any
Expand Down Expand Up @@ -165,7 +286,7 @@ export async function dispatchLocatorAction(
const locator = asActionable(target);
switch (action.kind) {
case 'tap':
await locator.click({ timeout, ...heldKeys(action) });
await clickControl(target, 'tap', { timeout, signal: operation.signal, ...heldKeys(action) });
return;
case 'doubleTap':
await locator.dblclick({ timeout, ...heldKeys(action) });
Expand Down
27 changes: 26 additions & 1 deletion packages/web/src/in-page/read-semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,28 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
return !(rect.width > 0 && rect.height > 0);
};

/**
* True for a checkbox or radio hidden only by having no box, under a shown
* label of its own that draws it, as in Element Plus. Chrome's tree keeps
* such an input, and without it the model reads the label text with no
* checked state. A tap clicks the label in its place (`pickStandIn` in
* `actions.ts`), which needs a box (so not `display: contents`) and refuses
* when the label's centre lands on a link or other control. This rule is
* stricter: a label that is one, or holds one anywhere, does not count.
*/
const isDrawnByLabel = (el: Element, style: CSSStyleDeclaration | undefined): boolean => {
if (!(el instanceof HTMLInputElement) || (el.type !== 'checkbox' && el.type !== 'radio')) return false;
if (style?.visibility !== 'visible' || isSkippedContent(el)) return false;
const INTERACTIVE = 'a,button,input,select,textarea,summary,[contenteditable],[role="button"],[role="link"]';
Comment thread
samanyudas marked this conversation as resolved.
Resolved
return associatedLabels(el).some(
(label) =>
styleOf(label)?.display !== 'contents' &&
!isHidden(label) &&
!label.matches(INTERACTIVE) &&
!Array.from(label.querySelectorAll(INTERACTIVE)).some((inner) => inner !== el),
);
};

/**
* What takes the element and everything under it out of the tree walk: an
* `aria-hidden` or inert subtree, which the accessibility tree drops though
Expand Down Expand Up @@ -1574,14 +1596,17 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
}

let nextParent = parent;
const drawnByLabel = hidden && isDrawnByLabel(el, style);
// An empty painted rectangle carries no semantics to be "interesting" by and
// is still something a person sees and aims at; `roleOf` names it `box`.
if (!hidden && (isInteresting(el) || isVisibleEmptyBox(el))) {
if ((!hidden || drawnByLabel) && (isInteresting(el) || isVisibleEmptyBox(el))) {
if (nodes.length >= maxNodes) {
truncated = true;
return;
}
nextParent = include(el, parent, style);
// Listed on purpose, so not "hidden", as a select's options are below.
if (drawnByLabel) nodes[nextParent]!.states.hidden = false;
}
// A closed select paints none of its options, so the hidden test would
// drop every one of them — and a model shown `combobox "Category"` alone
Expand Down
4 changes: 4 additions & 0 deletions packages/web/tests/crosscheck/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# page | oracle field | role "name" | ours <value> | theirs <value> | reason
# Generated by E2E_CROSSCHECK_UPDATE=1; edit only the reasons. See tests/crosscheck/expectations.ts.
benchmark: file-round-trip | chrome name | button "" | ours | theirs Choose File | An unlabeled file input shows the browser's localized button text, which the page cannot read; Playwright reports it too, the tree leaves the input unnamed rather than guess the locale
fixture: controls drawn by their label | chrome missing | checkbox "" | ours no node | theirs checkbox | A checkbox with no box whose only label is not rendered shows a person nothing to aim at; the tree lists one only while a label of its own draws it
fixture: controls drawn by their label | chrome missing | checkbox "Accept the terms" | ours no node | theirs checkbox | A tap on a checkbox with no box clicks its label, which it refuses when the label's centre lands on a link, so the click follows no link; the tree leaves the checkbox out when its label holds a link anywhere, a stricter rule, rather than list one a tap may not reach
fixture: controls drawn by their label | chrome missing | checkbox "Contents" | ours no node | theirs checkbox | A `display: contents` label has no box, so a tap cannot click it in place of a checkbox with no box; the tree leaves the checkbox out and the model taps the label text, which sets it
fixture: controls drawn by their label | chrome missing | checkbox "Unlabelled" | ours no node | theirs checkbox | An aria-label draws nothing: a checkbox with no box and no label element shows a person nothing to aim at, so the tree leaves it out
fixture: disabled states | chrome disabled | group "Shipping" | ours true | theirs false | `:disabled` matches a disabled fieldset itself; the tree keeps that so the model reads why the controls inside are disabled. Chrome and Playwright mark only the controls
fixture: disabled states | chrome selected | option "Poland" | ours true | theirs false | Chrome drops the selected state of an option in a disabled select; Playwright agrees with the tree that it is the value
fixture: generated content | chrome name | link "Sign out" | ours Sign out | theirs | Chrome names a link whose only content is an icon-font glyph by the glyph, which is nothing once dropped; the tree falls back to its title so the model reads the word a person hovering it sees
Expand Down
15 changes: 15 additions & 0 deletions packages/web/tests/crosscheck/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ export const FIXTURE_PAGES: readonly FixturePage[] = [
<label><input type="checkbox" aria-checked="false" checked> Native wins</label>
`,
},
{
name: 'controls drawn by their label',
html: `
<style>.shrunk { opacity: 0; width: 0; height: 0; margin: 0; position: absolute; z-index: -1 }</style>
<label><input type="checkbox">Plain</label>
<label><span><input class="shrunk" type="checkbox"><span class="box"></span></span><span>Agree</span></label>
<label><input class="shrunk" type="checkbox" checked>Newsletter</label>
<label><input class="shrunk" type="radio" name="size">Large</label>
<input class="shrunk" type="checkbox" id="unlabelled-shrunk" aria-label="Unlabelled">
<input class="shrunk" type="checkbox" id="hidden-label"><label for="hidden-label" style="display: none">Hidden label</label>
<label><input class="shrunk" type="checkbox" style="visibility: hidden">Invisible</label>
<label style="display: contents"><input class="shrunk" type="checkbox"><span class="box"></span>Contents</label>
<label><input class="shrunk" type="checkbox"><span class="box"></span>Accept <a href="#terms">the terms</a></label>
`,
},
{
name: 'disabled states',
html: `
Expand Down
Loading
Loading