From 95cb7e705802d9f03df2d09dc157931f3341b5d1 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Sun, 25 Oct 2026 03:50:48 +1030 Subject: [PATCH 1/9] fix(web): check a radio or checkbox through its own label when the label covers it Element Plus hides the native input under its label's styled spans or gives it no box, so Playwright's hit-target check refused it. check, uncheck, and tap now click the label at the input's point when the element at that point is the label's own content, or the input's first label with a box when the input has none; anything else on top, a disabled input, an input on top itself, or a boxless input whose labels are all hidden is clicked as before. One in-page read decides whether a label stands in, so a tap on anything else pays that read and keeps locator.click, under one deadline. A locator that never appears still fails NOT_ACTIONABLE within one timeout. Fixes #1276 Co-Authored-By: Claude Fable 5.1 --- .changeset/check-through-label.md | 5 + docs/reference/screen.mdx | 5 + packages/web/src/actions.ts | 85 +++++++++++++- .../tests/integration/check-actions.test.ts | 106 ++++++++++++++++++ 4 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 .changeset/check-through-label.md diff --git a/.changeset/check-through-label.md b/.changeset/check-through-label.md new file mode 100644 index 0000000000..593e095703 --- /dev/null +++ b/.changeset/check-through-label.md @@ -0,0 +1,5 @@ +--- +"@e2e-dev/web": patch +--- + +`check`, `uncheck`, and `tap` reach a native checkbox or radio that its own label covers, or that has no box of its own, as Element Plus draws its radio buttons, radios, and checkboxes, by clicking the label at the control's point; a control covered by anything else still fails `ACTION_FAILED`. diff --git a/docs/reference/screen.mdx b/docs/reference/screen.mdx index ca0dde8aee..d848e121b9 100644 --- a/docs/reference/screen.mdx +++ b/docs/reference/screen.mdx @@ -754,6 +754,11 @@ check(options?: ActionOptions): Promise; await screen.getByRole('checkbox', 'Remember me').check(); ``` +On the web engine, a native checkbox or radio that its own label covers +(Element Plus hides the input under the label's styled spans), or that has +no box of its own, is clicked through that label, by `check`, `uncheck`, and +`tap`. A control covered by anything else still fails `ACTION_FAILED`. + #### `uncheck` ```ts diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index dff2723d75..f7181fd29c 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -60,7 +60,7 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con retryable: false, }); } - await element.click({ timeout: remaining() }); + await clickControl({ kind: 'element', element }, { timeout: remaining() }); const unchanged = (detail = ''): EngineError => new EngineError('NOT_ACTIONABLE', `${verb} clicked the control but its checked state did not change${detail}`, { retryable: false, @@ -88,6 +88,87 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con } } +/** + * The label a click on a native checkbox or radio goes through instead of + * the control itself. Without `position` Playwright clicks the label's + * centre, which may be a link elsewhere in the label. + */ +interface StandIn { + labelIndex: number; + position?: { x: number; y: number }; +} + +/** + * 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 (` + * intercepts pointer events`, `element is not visible`) though a user's click + * there reaches it through the label. + */ +function pickStandIn(node: Element): StandIn | null { + if (!(node instanceof HTMLInputElement) || (node.type !== 'checkbox' && node.type !== 'radio') || node.disabled) { + return null; + } + const labels = [...(node.labels ?? [])]; + if (labels.length === 0) return null; + node.scrollIntoView({ block: 'nearest', inline: 'nearest' }); + const box = node.getBoundingClientRect(); + const hasBox = ({ width, height }: DOMRect): boolean => width > 0 && height > 0; + if (!hasBox(box)) { + const index = labels.findIndex((label) => hasBox(label.getBoundingClientRect())); + return index === -1 ? null : { labelIndex: index }; + } + const root = node.getRootNode(); + if (!(root instanceof Document) && !(root instanceof ShadowRoot)) return null; + const hit = root.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2); + if (hit === null || hit === node) return null; + for (const [index, label] of labels.entries()) { + if (!label.contains(hit)) continue; + const outer = label.getBoundingClientRect(); + const x = box.left + box.width / 2 - outer.left; + const y = box.top + box.height / 2 - outer.top; + const inside = x >= 0 && y >= 0 && x <= outer.width && y <= outer.height; + return inside ? { labelIndex: index, position: { x, y } } : { labelIndex: index }; + } + return null; +} + +/** + * Clicks a control with Playwright's actionability checks, through its own + * label when `pickStandIn` names one. The checks then run on the label: its + * own content passes, anything else on top, such as a modal, still fails + * NOT_ACTIONABLE. + */ +async function clickControl( + target: ActionTarget, + options: { timeout: number; modifiers?: KeyModifier[] }, +): Promise { + const deadline = new Deadline(options.timeout); + const remaining = (): number => Math.max(1, deadline.remaining()); + const standIn = + target.kind === 'locator' + ? await target.locator.evaluate(pickStandIn, undefined, { timeout: options.timeout }) + : await target.element.evaluate(pickStandIn); + const labelAt = (node: Element, index: number): Element | null => + node instanceof HTMLInputElement ? (node.labels?.[index] ?? null) : null; + const label = + standIn === null + ? null + : target.kind === 'locator' + ? (await target.locator.evaluateHandle(labelAt, standIn.labelIndex)).asElement() + : (await target.element.evaluateHandle(labelAt, standIn.labelIndex)).asElement(); + if (standIn === null || label === null) { + await asActionable(target).click({ ...options, timeout: remaining() }); + return; + } + const { position } = standIn; + try { + await label.click({ ...options, timeout: remaining(), ...(position === undefined ? {} : { position }) }); + } finally { + void label.dispose().catch(() => undefined); + } +} + /** Whether a checkable element is a radio, which a click can select but never clear. */ function isRadio(element: ElementHandle): Promise { return element.evaluate( @@ -110,7 +191,7 @@ export async function dispatchLocatorAction( const locator = asActionable(target); switch (action.kind) { case 'tap': - await locator.click({ timeout, ...heldKeys(action) }); + await clickControl(target, { timeout, ...heldKeys(action) }); return; case 'doubleTap': await locator.dblclick({ timeout, ...heldKeys(action) }); diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index 85cbba9ea5..4e22048ace 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -171,3 +171,109 @@ describe('a control gone before the click', () => { expect(await perform(target, { kind: 'check' })).toMatchObject({ code: 'NODE_STALE', retryable: true }); }); }); + +const ELEMENT_PLUS_CSS = ` +.el-radio-button{outline:none;display:inline-block;position:relative} +.el-radio-button__original-radio{opacity:0;z-index:-1;outline:none;position:absolute} +.el-radio-button__inner{white-space:nowrap;vertical-align:middle;background:#fff;border:1px solid #dcdfe6;line-height:1;cursor:pointer;display:inline-block;position:relative;padding:8px 15px} +.el-checkbox{cursor:pointer;display:inline-flex;align-items:center;position:relative} +.el-checkbox__input{white-space:nowrap;cursor:pointer;outline:none;display:inline-flex;position:relative} +.el-checkbox__original{opacity:0;z-index:-1;outline:none;width:0;height:0;margin:0;position:absolute} +.el-checkbox__inner{display:inline-block;position:relative;border:1px solid #dcdfe6;width:14px;height:14px;background:#fff;z-index:1} +.el-radio{cursor:pointer;display:inline-flex;align-items:center;position:relative} +.el-radio__input{white-space:nowrap;cursor:pointer;outline:none;display:inline-flex;position:relative} +.el-radio__original{opacity:0;z-index:-1;outline:none;margin:0;position:absolute;top:0;bottom:0;left:0;right:0} +.el-radio__inner{border:1px solid #dcdfe6;border-radius:100%;width:14px;height:14px;background:#fff;position:relative;display:inline-block} +.modal{position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:10} +`; + +const ELEMENT_PLUS_CONTROLS = ` + + + + +`; + +const ELEMENT_PLUS_PAGE = `${ELEMENT_PLUS_CONTROLS}`; + +const ELEMENT_PLUS_CASES = [ + ['radio-button', '#install'], + ['checkbox', '#agree'], + ['radio', '#large'], +] as const; + +describe.each(KINDS)('a control its own label covers, through the %s target', (kind) => { + it.each(ELEMENT_PLUS_CASES)('checks an Element Plus %s', async (_, selector) => { + await page.setContent(ELEMENT_PLUS_PAGE); + expect(await perform(await targetOf(kind, selector), { kind: 'check' })).toBeUndefined(); + expect(await page.isChecked(selector)).toBe(true); + }); + + it.each(ELEMENT_PLUS_CASES)('taps an Element Plus %s', async (_, selector) => { + await page.setContent(ELEMENT_PLUS_PAGE); + expect(await perform(await targetOf(kind, selector), { kind: 'tap' })).toBeUndefined(); + expect(await page.isChecked(selector)).toBe(true); + }); + + it.each(ELEMENT_PLUS_CASES)('still refuses an Element Plus %s under a modal', async (_, selector) => { + await page.setContent(`${ELEMENT_PLUS_PAGE}`); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, selector), action)).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await page.isChecked(selector)).toBe(false); + } + }); + + it('checks a boxless checkbox through its first visible label, past a hidden one', async () => { + await page.setContent(` + + + `); + expect(await perform(await targetOf(kind, '#c'), { kind: 'check' })).toBeUndefined(); + expect(await page.isChecked('#c')).toBe(true); + }); + + it('still refuses a boxless checkbox whose every label is hidden', async () => { + await page.setContent(` + + `); + expect(await perform(await targetOf(kind, '#c'), { kind: 'check' })).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await page.isChecked('#c')).toBe(false); + }); + + it('still refuses a disabled Element Plus radio-button', async () => { + await page.setContent(ELEMENT_PLUS_PAGE.replace('id="install"', 'id="install" disabled')); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await page.isChecked('#install')).toBe(false); + } + }); + + it('checks an Element Plus radio-button inside a shadow root', async () => { + await page.setContent(`
`); + expect(await perform(await targetOf(kind, '#install'), { kind: 'check' })).toBeUndefined(); + expect(await page.isChecked('#install')).toBe(true); + }); +}); + +describe('a tap on a locator that never appears', () => { + it('fails NOT_ACTIONABLE within one deadline, as a plain click does', async () => { + await page.setContent('

Nothing to tap

'); + const started = Date.now(); + const error = await perform({ kind: 'locator', locator: page.locator('#missing') }, { kind: 'tap' }); + expect(Date.now() - started).toBeLessThan(3500); + expect(error).toMatchObject({ code: 'NOT_ACTIONABLE', retryable: false }); + expect(error?.message).toMatch(/^tap did not become actionable in time: .*Timeout 2000ms exceeded/); + expect(error?.message).toContain("waiting for locator('#missing')"); + }); +}); + +describe('a control its own label covers, inside a frame', () => { + it('checks an Element Plus radio-button', async () => { + await page.setContent(`

Outer

`); + const locator = page.frameLocator('iframe').locator('#install'); + expect(await perform({ kind: 'locator', locator }, { kind: 'check' })).toBeUndefined(); + expect(await locator.isChecked()).toBe(true); + }); +}); From c88fd0b0a9cd99a5f1f8c1b4de6250d19cae9e79 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Sun, 25 Oct 2026 04:26:46 +1030 Subject: [PATCH 2/9] fix(web): skip the label stand-in for disabled fieldsets, hidden labels, and links over the input A control a disabled fieldset holds is refused by :disabled, not only the attribute. A boxless control picks a label that is rendered (checkVisibility), since visibility: hidden keeps its box. No label stands in when the element at the click point, the input's centre or a boxless label's centre, is a link, button, or other interactive descendant of the label: the click would press that instead, and a tap could follow a link. The locator's label resolution runs under the action's remaining deadline. Docs: uncheck reaches a checkbox only, the boxless case needs a visible label, and a link or button in the label still fails. Co-Authored-By: Claude Fable 5.1 --- docs/reference/screen.mdx | 6 ++- packages/web/src/actions.ts | 38 ++++++++++----- .../tests/integration/check-actions.test.ts | 48 +++++++++++++++++++ 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/docs/reference/screen.mdx b/docs/reference/screen.mdx index d848e121b9..1ca3fb07d4 100644 --- a/docs/reference/screen.mdx +++ b/docs/reference/screen.mdx @@ -756,8 +756,10 @@ await screen.getByRole('checkbox', 'Remember me').check(); On the web engine, a native checkbox or radio that its own label covers (Element Plus hides the input under the label's styled spans), or that has -no box of its own, is clicked through that label, by `check`, `uncheck`, and -`tap`. A control covered by anything else still fails `ACTION_FAILED`. +no box of its own and a visible label, is clicked through that label by +`check` and `tap`, and by `uncheck` for a checkbox. A control covered by +anything else, a link or button in its label included, still fails +`ACTION_FAILED`. #### `uncheck` diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index f7181fd29c..499452fb1c 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -90,8 +90,8 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con /** * The label a click on a native checkbox or radio goes through instead of - * the control itself. Without `position` Playwright clicks the label's - * centre, which may be a link elsewhere in the label. + * the control itself, at the control's point when it has one, else at the + * label's centre. */ interface StandIn { labelIndex: number; @@ -106,24 +106,37 @@ interface StandIn { * there reaches it through the label. */ function pickStandIn(node: Element): StandIn | null { - if (!(node instanceof HTMLInputElement) || (node.type !== 'checkbox' && node.type !== 'radio') || node.disabled) { + if (!(node instanceof HTMLInputElement) || (node.type !== 'checkbox' && node.type !== 'radio') || node.matches(':disabled')) { return null; } const labels = [...(node.labels ?? [])]; - if (labels.length === 0) return null; + 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 pressesInteractive = (label: HTMLLabelElement, hit: Element | null): boolean => { + const interactive = hit?.closest(INTERACTIVE) ?? null; + return interactive !== null && label.contains(interactive); + }; node.scrollIntoView({ block: 'nearest', inline: 'nearest' }); const box = node.getBoundingClientRect(); - const hasBox = ({ width, height }: DOMRect): boolean => width > 0 && height > 0; if (!hasBox(box)) { - const index = labels.findIndex((label) => hasBox(label.getBoundingClientRect())); + const index = labels.findIndex((label) => { + const outer = label.getBoundingClientRect(); + return ( + hasBox(outer) && + label.checkVisibility({ visibilityProperty: true }) && + !pressesInteractive(label, root.elementFromPoint(...centre(outer))) + ); + }); return index === -1 ? null : { labelIndex: index }; } - const root = node.getRootNode(); - if (!(root instanceof Document) && !(root instanceof ShadowRoot)) return null; - const hit = root.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2); + const hit = root.elementFromPoint(...centre(box)); if (hit === null || hit === node) return null; for (const [index, label] of labels.entries()) { if (!label.contains(hit)) continue; + if (pressesInteractive(label, hit)) return null; const outer = label.getBoundingClientRect(); const x = box.left + box.width / 2 - outer.left; const y = box.top + box.height / 2 - outer.top; @@ -135,9 +148,8 @@ function pickStandIn(node: Element): StandIn | null { /** * Clicks a control with Playwright's actionability checks, through its own - * label when `pickStandIn` names one. The checks then run on the label: its - * own content passes, anything else on top, such as a modal, still fails - * NOT_ACTIONABLE. + * 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. */ async function clickControl( target: ActionTarget, @@ -155,7 +167,7 @@ async function clickControl( standIn === null ? null : target.kind === 'locator' - ? (await target.locator.evaluateHandle(labelAt, standIn.labelIndex)).asElement() + ? (await target.locator.evaluateHandle(labelAt, standIn.labelIndex, { timeout: remaining() })).asElement() : (await target.element.evaluateHandle(labelAt, standIn.labelIndex)).asElement(); if (standIn === null || label === null) { await asActionable(target).click({ ...options, timeout: remaining() }); diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index 4e22048ace..1902a1da6b 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -232,6 +232,54 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k expect(await page.isChecked('#c')).toBe(true); }); + it('checks a boxless checkbox past a label hidden by visibility, which keeps its box', async () => { + await page.setContent(` + + + `); + expect(await perform(await targetOf(kind, '#c'), { kind: 'check' })).toBeUndefined(); + expect(await page.isChecked('#c')).toBe(true); + }); + + it('still refuses a radio under a link in its own label, and follows no link', async () => { + await page.setContent(` + `); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ + code: 'NOT_ACTIONABLE', + message: expect.stringContaining('intercepts pointer events'), + }); + expect(await page.isChecked('#install')).toBe(false); + expect(page.url()).not.toContain('#went'); + } + }); + + it('still refuses a boxless checkbox whose visible label has a link at its centre', async () => { + await page.setContent(` + + `); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#c'), action)).toMatchObject({ + code: 'NOT_ACTIONABLE', + message: expect.stringContaining('not visible'), + }); + expect(await page.isChecked('#c')).toBe(false); + expect(page.url()).not.toContain('#went'); + } + }); + + it('still refuses an Element Plus radio-button a disabled fieldset holds', async () => { + await page.setContent(`
${ELEMENT_PLUS_CONTROLS}
`); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ + code: 'NOT_ACTIONABLE', + message: expect.stringContaining('not enabled'), + }); + expect(await page.isChecked('#install')).toBe(false); + } + }); + it('still refuses a boxless checkbox whose every label is hidden', async () => { await page.setContent(` From dc700e8bcb52c02f41f7e29bf03473d19b3d9ff2 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Mon, 26 Oct 2026 11:48:02 +1030 Subject: [PATCH 3/9] fix(web): choose the label stand-in past loading masks and wait for an unrendered control The stand-in was decided once from elementFromPoint, so a loading mask on top, or a dialog not open yet, sent the click to the input, which its label then covered until the deadline. The choice now reads the stack at the input's point past anything outside the control and its labels, so Playwright's checks on the label wait the mask out, and is polled while nothing of the control is rendered, failing NOT_ACTIONABLE at the deadline. One evaluateHandle returns the label itself, so the index and the second resolve are gone. A point outside the label's box clicks the input as before, and a tap on anything else returns before scrolling. Co-Authored-By: Claude Opus 5.5 --- .changeset/check-through-label.md | 2 +- docs/reference/screen.mdx | 9 +- packages/web/src/actions.ts | 133 +++++++++++------- .../tests/integration/check-actions.test.ts | 43 +++++- 4 files changed, 124 insertions(+), 63 deletions(-) diff --git a/.changeset/check-through-label.md b/.changeset/check-through-label.md index 593e095703..7a5689e801 100644 --- a/.changeset/check-through-label.md +++ b/.changeset/check-through-label.md @@ -2,4 +2,4 @@ "@e2e-dev/web": patch --- -`check`, `uncheck`, and `tap` reach a native checkbox or radio that its own label covers, or that has no box of its own, as Element Plus draws its radio buttons, radios, and checkboxes, by clicking the label at the control's point; a control covered by anything else still fails `ACTION_FAILED`. +`check`, `uncheck`, and `tap` click a checkbox or radio hidden under its own label (as in Element Plus) through that label. Anything else covering it still fails `ACTION_FAILED`. diff --git a/docs/reference/screen.mdx b/docs/reference/screen.mdx index 1ca3fb07d4..8c7ce59ee7 100644 --- a/docs/reference/screen.mdx +++ b/docs/reference/screen.mdx @@ -754,12 +754,9 @@ check(options?: ActionOptions): Promise; await screen.getByRole('checkbox', 'Remember me').check(); ``` -On the web engine, a native checkbox or radio that its own label covers -(Element Plus hides the input under the label's styled spans), or that has -no box of its own and a visible label, is clicked through that label by -`check` and `tap`, and by `uncheck` for a checkbox. A control covered by -anything else, a link or button in its label included, still fails -`ACTION_FAILED`. +On the web engine, a checkbox or radio hidden under its own label (as in +Element Plus) is clicked through that label. Anything else covering it still +fails `ACTION_FAILED`. #### `uncheck` diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index 499452fb1c..fd49be12ef 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -60,7 +60,7 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con retryable: false, }); } - await clickControl({ kind: 'element', element }, { timeout: remaining() }); + await clickControl({ kind: 'element', element }, verb, { timeout: remaining(), signal: operation.signal }); const unchanged = (detail = ''): EngineError => new EngineError('NOT_ACTIONABLE', `${verb} clicked the control but its checked state did not change${detail}`, { retryable: false, @@ -89,23 +89,23 @@ async function setChecked(target: ActionTarget, checked: boolean, operation: Con } /** - * The label a click on a native checkbox or radio goes through instead of - * the control itself, at the control's point when it has one, else at the - * label's centre. + * 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. */ -interface StandIn { - labelIndex: number; - position?: { x: number; y: number }; -} +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 (` * intercepts pointer events`, `element is not visible`) though a user's click - * there reaches it through the label. + * 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): StandIn | null { +function pickStandIn(node: Element, unrendered: string): HTMLLabelElement | null { if (!(node instanceof HTMLInputElement) || (node.type !== 'checkbox' && node.type !== 'radio') || node.matches(':disabled')) { return null; } @@ -115,67 +115,92 @@ function pickStandIn(node: Element): StandIn | 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 pressesInteractive = (label: HTMLLabelElement, hit: Element | null): boolean => { - const interactive = hit?.closest(INTERACTIVE) ?? null; - return interactive !== null && label.contains(interactive); - }; + 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 index = labels.findIndex((label) => { - const outer = label.getBoundingClientRect(); - return ( - hasBox(outer) && - label.checkVisibility({ visibilityProperty: true }) && - !pressesInteractive(label, root.elementFromPoint(...centre(outer))) - ); - }); - return index === -1 ? null : { labelIndex: index }; - } - const hit = root.elementFromPoint(...centre(box)); - if (hit === null || hit === node) return null; - for (const [index, label] of labels.entries()) { - if (!label.contains(hit)) continue; - if (pressesInteractive(label, hit)) return null; - const outer = label.getBoundingClientRect(); - const x = box.left + box.width / 2 - outer.left; - const y = box.top + box.height / 2 - outer.top; - const inside = x >= 0 && y >= 0 && x <= outer.width && y <= outer.height; - return inside ? { labelIndex: index, position: { x, y } } : { labelIndex: index }; + 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 + ); } - return 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. + * 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, - options: { timeout: number; modifiers?: KeyModifier[] }, + verb: 'tap' | 'check' | 'uncheck', + options: { timeout: number; signal: AbortSignal; modifiers?: KeyModifier[] }, ): Promise { + const { signal, ...click } = options; const deadline = new Deadline(options.timeout); const remaining = (): number => Math.max(1, deadline.remaining()); - const standIn = - target.kind === 'locator' - ? await target.locator.evaluate(pickStandIn, undefined, { timeout: options.timeout }) - : await target.element.evaluate(pickStandIn); - const labelAt = (node: Element, index: number): Element | null => - node instanceof HTMLInputElement ? (node.labels?.[index] ?? null) : null; - const label = - standIn === null - ? null - : target.kind === 'locator' - ? (await target.locator.evaluateHandle(labelAt, standIn.labelIndex, { timeout: remaining() })).asElement() - : (await target.element.evaluateHandle(labelAt, standIn.labelIndex)).asElement(); - if (standIn === null || label === null) { - await asActionable(target).click({ ...options, timeout: remaining() }); + // Set inside the poll; the assertion keeps TypeScript from narrowing it to null here. + let label = null as ElementHandle | null; + 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(); + 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 }), + }); + if (label === null) { + await asActionable(target).click({ ...click, timeout: remaining() }); return; } - const { position } = standIn; try { - await label.click({ ...options, timeout: remaining(), ...(position === undefined ? {} : { position }) }); + const position = await label.evaluate(controlPoint); + await label.click({ ...click, timeout: remaining(), ...(position === null ? {} : { position }) }); } finally { void label.dispose().catch(() => undefined); } @@ -203,7 +228,7 @@ export async function dispatchLocatorAction( const locator = asActionable(target); switch (action.kind) { case 'tap': - await clickControl(target, { timeout, ...heldKeys(action) }); + await clickControl(target, 'tap', { timeout, signal: operation.signal, ...heldKeys(action) }); return; case 'doubleTap': await locator.dblclick({ timeout, ...heldKeys(action) }); diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index 1902a1da6b..87ecbff56d 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -223,6 +223,40 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k } }); + it.each(ELEMENT_PLUS_CASES)('waits out a loading mask over an Element Plus %s', async (_, selector) => { + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + await page.setContent(`${ELEMENT_PLUS_PAGE} + `); + expect(await perform(await targetOf(kind, selector), action)).toBeUndefined(); + expect(await page.isChecked(selector)).toBe(true); + } + }); + + it.each(ELEMENT_PLUS_CASES)('waits for an Element Plus %s in a dialog that opens later', async (_, selector) => { + for (const display of ['display:none', 'visibility:hidden']) { + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + await page.setContent(`
${ELEMENT_PLUS_CONTROLS}
+ `); + expect(await perform(await targetOf(kind, selector), action)).toBeUndefined(); + expect(await page.isChecked(selector)).toBe(true); + } + } + }); + + it('still refuses a radio whose label covers it from outside the label box', async () => { + await page.setContent(` + `); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#r'), action)).toMatchObject({ + code: 'NOT_ACTIONABLE', + message: expect.stringContaining('intercepts pointer events'), + }); + expect(await page.isChecked('#r')).toBe(false); + } + }); + it('checks a boxless checkbox through its first visible label, past a hidden one', async () => { await page.setContent(` @@ -284,8 +318,13 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k await page.setContent(` `); - expect(await perform(await targetOf(kind, '#c'), { kind: 'check' })).toMatchObject({ code: 'NOT_ACTIONABLE' }); - expect(await page.isChecked('#c')).toBe(false); + for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { + expect(await perform(await targetOf(kind, '#c'), action)).toMatchObject({ + code: 'NOT_ACTIONABLE', + message: `${action.kind} did not become actionable in time: the control and its labels are not visible`, + }); + expect(await page.isChecked('#c')).toBe(false); + } }); it('still refuses a disabled Element Plus radio-button', async () => { From 0c51c8410f0c2c7ee44d12dde8f95ebf2f0a6823 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Mon, 26 Oct 2026 12:04:25 +1030 Subject: [PATCH 4/9] fix(web): click no control after a cancelled stand-in read, and dispose the null handle The surface abandons a cancelled or timed-out operation without stopping it, so a stand-in read still in flight went on to click. The signal is now checked right before both click paths. The handle `pickStandIn` returns for a control clicked as itself is disposed instead of living until the page navigates. Co-Authored-By: Claude Opus 5.5 --- packages/web/src/actions.ts | 4 ++++ .../tests/integration/check-actions.test.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index fd49be12ef..e3595a2eff 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -183,6 +183,7 @@ async function clickControl( ? await target.locator.evaluateHandle(pickStandIn, UNRENDERED, { timeout: remaining() }) : await target.element.evaluateHandle(pickStandIn, UNRENDERED); label = handle.asElement(); + if (label === null) void handle.dispose().catch(() => undefined); return true; } catch (cause) { if (message(cause).includes(UNRENDERED)) return undefined; @@ -194,12 +195,15 @@ async function clickControl( 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 === null) { + 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); diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index 87ecbff56d..dfbe69f0e8 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -364,3 +364,22 @@ describe('a control its own label covers, inside a frame', () => { expect(await locator.isChecked()).toBe(true); }); }); + +describe('an action cancelled while its stand-in read is in flight', () => { + it.each(KINDS)('clicks nothing through the %s target', async (kind) => { + for (const [selector, action] of [['#install', { kind: 'tap' }], ['#install', { kind: 'check' }], ['#plain', { kind: 'tap' }]] as const) { + await page.setContent(`${ELEMENT_PLUS_PAGE}`); + const target = await targetOf(kind, selector); + // Holds the page's main thread, so the read waits behind it until after the abort. + await page.evaluate(() => setTimeout(() => { const until = Date.now() + 400; while (Date.now() < until); }, 0)); + const controller = new AbortController(); + setTimeout(() => controller.abort(new Error('cancelled')), 100); + await expect( + dispatchLocatorAction(target, action, { timeoutMs: 2000, signal: controller.signal }, () => { + throw new Error('no second target'); + }), + ).rejects.toThrow('cancelled'); + expect(await page.isChecked(selector)).toBe(false); + } + }); +}); From 779130e08677961826041334a7add9567859d79c Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 27 Oct 2026 21:46:56 +1030 Subject: [PATCH 5/9] refactor(web): type the label stand-in as undefined instead of a null cast A `let` initialised to `null` narrows to `null`, and TypeScript does not see the assignment inside the poll callback, so the old code needed an `as` cast and a comment. Declared without an initialiser, the variable keeps its declared type after the poll. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- packages/web/src/actions.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index e3595a2eff..c72c693ab5 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -167,8 +167,7 @@ async function clickControl( const { signal, ...click } = options; const deadline = new Deadline(options.timeout); const remaining = (): number => Math.max(1, deadline.remaining()); - // Set inside the poll; the assertion keeps TypeScript from narrowing it to null here. - let label = null as ElementHandle | null; + let label: ElementHandle | undefined; let firstRead = true; await pollCondition({ deadline, @@ -182,8 +181,8 @@ async function clickControl( target.kind === 'locator' ? await target.locator.evaluateHandle(pickStandIn, UNRENDERED, { timeout: remaining() }) : await target.element.evaluateHandle(pickStandIn, UNRENDERED); - label = handle.asElement(); - if (label === null) void handle.dispose().catch(() => undefined); + label = handle.asElement() ?? undefined; + if (label === undefined) void handle.dispose().catch(() => undefined); return true; } catch (cause) { if (message(cause).includes(UNRENDERED)) return undefined; @@ -196,7 +195,7 @@ async function clickControl( 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 === null) { + if (label === undefined) { signal.throwIfAborted(); await asActionable(target).click({ ...click, timeout: remaining() }); return; From 2e0883dea58da4b15536959a8cf768f81d4a9dc9 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 27 Oct 2026 21:46:56 +1030 Subject: [PATCH 6/9] test(web): give the label refusal cases a 500ms deadline Each "still refuses" case waited out the 2s deadline twice (check, then tap). `perform` now takes a timeout, and those cases pass 500ms. The file drops from about 102s to 48s locally. Co-Authored-By: Claude Opus 5.5 --- .../tests/integration/check-actions.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index dfbe69f0e8..6954e82f9e 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -55,10 +55,13 @@ async function targetOf(kind: (typeof KINDS)[number], selector: string): Promise return { kind, element }; } +/** A refusal waits out the whole deadline, so the cases that expect one take a short one. */ +const REFUSAL_TIMEOUT_MS = 500; + /** Performs one action and returns the contract error it failed with, classified as the engine reports it. */ -async function perform(target: ActionTarget, action: LocatorAction): Promise { +async function perform(target: ActionTarget, action: LocatorAction, timeoutMs = 2000): Promise { try { - await dispatchLocatorAction(target, action, { timeoutMs: 2000, signal: new AbortController().signal }, () => { + await dispatchLocatorAction(target, action, { timeoutMs, signal: new AbortController().signal }, () => { throw new Error('no second target'); }); return undefined; @@ -218,7 +221,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k it.each(ELEMENT_PLUS_CASES)('still refuses an Element Plus %s under a modal', async (_, selector) => { await page.setContent(`${ELEMENT_PLUS_PAGE}`); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, selector), action)).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await perform(await targetOf(kind, selector), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE' }); expect(await page.isChecked(selector)).toBe(false); } }); @@ -249,7 +252,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k style="position:absolute;left:200px;top:100px;opacity:0;z-index:-1">`); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#r'), action)).toMatchObject({ + expect(await perform(await targetOf(kind, '#r'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE', message: expect.stringContaining('intercepts pointer events'), }); @@ -280,7 +283,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k `); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ + expect(await perform(await targetOf(kind, '#install'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE', message: expect.stringContaining('intercepts pointer events'), }); @@ -294,7 +297,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k `); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#c'), action)).toMatchObject({ + expect(await perform(await targetOf(kind, '#c'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE', message: expect.stringContaining('not visible'), }); @@ -306,7 +309,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k it('still refuses an Element Plus radio-button a disabled fieldset holds', async () => { await page.setContent(`
${ELEMENT_PLUS_CONTROLS}
`); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ + expect(await perform(await targetOf(kind, '#install'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE', message: expect.stringContaining('not enabled'), }); @@ -319,7 +322,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k `); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#c'), action)).toMatchObject({ + expect(await perform(await targetOf(kind, '#c'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE', message: `${action.kind} did not become actionable in time: the control and its labels are not visible`, }); @@ -330,7 +333,7 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k it('still refuses a disabled Element Plus radio-button', async () => { await page.setContent(ELEMENT_PLUS_PAGE.replace('id="install"', 'id="install" disabled')); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) { - expect(await perform(await targetOf(kind, '#install'), action)).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await perform(await targetOf(kind, '#install'), action, REFUSAL_TIMEOUT_MS)).toMatchObject({ code: 'NOT_ACTIONABLE' }); expect(await page.isChecked('#install')).toBe(false); } }); From dd7d358056a871d956f924cc24b3428fcb1db1b9 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Fri, 6 Nov 2026 22:26:43 +1030 Subject: [PATCH 7/9] test(web): resolve the element target through ElementList, as an observed ref does Since #1571 an observed ref's handle is made on first use from the walk's in-page array. Building the check-actions element target the same way runs every label stand-in case on the path an agent step takes. Co-Authored-By: Claude Opus 5.5 --- packages/web/tests/integration/check-actions.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index e8080d3563..1d172b59a7 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -13,6 +13,7 @@ import { chromium, type Browser, type Page } from 'playwright-core'; import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; import type { LocatorAction } from 'e2e/engine'; import { classifyActionError, dispatchLocatorAction } from '../../src/actions.ts'; +import { ElementList } from '../../src/element-list.ts'; import type { ActionTarget } from '../../src/support.ts'; let browser: Browser; @@ -46,13 +47,15 @@ beforeEach(async () => { const KINDS = ['locator', 'element'] as const; -/** The control as the engine would hold it: a locator, or an element handle pinned by an observation. */ +/** + * The control as the engine would hold it: a locator, or the element handle + * an observed ref resolves to, made on first use from the walk's in-page array. + */ async function targetOf(kind: (typeof KINDS)[number], selector: string): Promise { const locator = page.locator(selector); if (kind === 'locator') return { kind, locator }; - const element = await locator.elementHandle(); - if (element === null) throw new Error(`no element for ${selector}`); - return { kind, element }; + const walk = new ElementList(await locator.evaluateHandle((node) => [node])); + return { kind, element: await walk.at(0) }; } /** A refusal waits out the whole deadline, so the cases that expect one take a short one. */ From e05a6f19a1acf83e90d5bde08afd842ca3ab92ae Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Fri, 6 Nov 2026 23:18:29 +1030 Subject: [PATCH 8/9] docs(web): limit the label-click claims to what the click checks The hit check runs at the point the click lands, so a cover elsewhere over the drawn box does not fail it, and uncheck refuses a native radio before any click. Co-Authored-By: Claude Opus 5.5 --- .changeset/check-through-label.md | 2 +- docs/reference/screen.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/check-through-label.md b/.changeset/check-through-label.md index 7a5689e801..13b098e244 100644 --- a/.changeset/check-through-label.md +++ b/.changeset/check-through-label.md @@ -2,4 +2,4 @@ "@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. Anything else covering it still fails `ACTION_FAILED`. +`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`. diff --git a/docs/reference/screen.mdx b/docs/reference/screen.mdx index 6254156634..b9a2046e38 100644 --- a/docs/reference/screen.mdx +++ b/docs/reference/screen.mdx @@ -761,8 +761,8 @@ 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 covering it still -fails `ACTION_FAILED`. +Element Plus) is clicked through that label. Anything else on top of the +point the click lands on still fails `ACTION_FAILED`. #### `uncheck` From ec2c689fb5ff0d267d45b388f7f41b25ee5403f9 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Sat, 7 Nov 2026 13:18:58 +1030 Subject: [PATCH 9/9] test(web): pin the clicked control and cover uncheck through a label A locator that matches another control after the state read must still click the control it read. Removing the pinned element from setChecked fails the new case. uncheck on an Element Plus checkbox clears it through its label, and on an Element Plus radio it is refused with no click. Turning the label stand-in off fails it. Co-Authored-By: Claude Opus 5.5 --- .../tests/integration/check-actions.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/web/tests/integration/check-actions.test.ts b/packages/web/tests/integration/check-actions.test.ts index 1d172b59a7..28b8bf6d7a 100644 --- a/packages/web/tests/integration/check-actions.test.ts +++ b/packages/web/tests/integration/check-actions.test.ts @@ -194,6 +194,34 @@ describe('a control gone before the click', () => { }); }); +describe('a locator that matches another control after the state read', () => { + it('clicks the control it read, not the one the locator matches now', async () => { + await page.setContent(` + + `); + const locator = page.locator('[data-pick]'); + const moved = new Proxy(locator, { + get(real, property) { + if (property === 'elementHandle') { + return async (options?: { timeout?: number }) => { + const element = await real.elementHandle(options); + await page.evaluate(() => { + document.getElementById('first')!.removeAttribute('data-pick'); + document.getElementById('second')!.setAttribute('data-pick', ''); + }); + return element; + }; + } + const value: unknown = Reflect.get(real, property); + return typeof value === 'function' ? value.bind(real) : value; + }, + }); + expect(await perform({ kind: 'locator', locator: moved }, { kind: 'check' })).toBeUndefined(); + expect(await page.isChecked('#first')).toBe(true); + expect(await page.isChecked('#second')).toBe(false); + }); +}); + const ELEMENT_PLUS_CSS = ` .el-radio-button{outline:none;display:inline-block;position:relative} .el-radio-button__original-radio{opacity:0;z-index:-1;outline:none;position:absolute} @@ -237,6 +265,19 @@ describe.each(KINDS)('a control its own label covers, through the %s target', (k expect(await page.isChecked(selector)).toBe(true); }); + it('unchecks an Element Plus checkbox, and refuses an Element Plus radio without clicking it', async () => { + await page.setContent(`${COUNT_CLICKS}${ELEMENT_PLUS_PAGE}`); + await page.evaluate(() => { + for (const id of ['agree', 'large']) (document.getElementById(id) as HTMLInputElement).checked = true; + }); + expect(await perform(await targetOf(kind, '#agree'), { kind: 'uncheck' })).toBeUndefined(); + expect(await page.isChecked('#agree')).toBe(false); + const before = await clicks(); + expect(await perform(await targetOf(kind, '#large'), { kind: 'uncheck' })).toMatchObject({ code: 'NOT_ACTIONABLE' }); + expect(await page.isChecked('#large')).toBe(true); + expect(await clicks()).toBe(before); + }); + it.each(ELEMENT_PLUS_CASES)('still refuses an Element Plus %s under a modal', async (_, selector) => { await page.setContent(`${ELEMENT_PLUS_PAGE}`); for (const action of [{ kind: 'check' }, { kind: 'tap' }] as const) {