From cc881fdb1f45773bbbaef1b397815680c35c10f2 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Tue, 2 Apr 2024 04:03:09 +0800 Subject: [PATCH] fix: content editable retarget (#29792) If `contenteditable` is wrapped into a button or `[role=button]`, `element.fill` will incorrectly retarget the closest button element. fix https://github.com/microsoft/playwright/issues/29813 --- packages/playwright-core/src/server/injected/injectedScript.ts | 2 +- tests/page/retarget.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 1b8160194d..8a73b9e423 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -459,7 +459,7 @@ export class InjectedScript { return null; if (behavior === 'none') return element; - if (!element.matches('input, textarea, select')) { + if (!element.matches('input, textarea, select') && !(element as any).isContentEditable) { if (behavior === 'button-link') element = element.closest('button, [role=button], a, [role=link]') || element; else diff --git a/tests/page/retarget.spec.ts b/tests/page/retarget.spec.ts index 203ac5bd16..4465643d77 100644 --- a/tests/page/retarget.spec.ts +++ b/tests/page/retarget.spec.ts @@ -250,7 +250,7 @@ it('input value retargeting', async ({ page, browserName }) => { } }); -it.fixme('selection retargeting', async ({ page, browserName }) => { +it('selection retargeting', async ({ page, browserName }) => { const cases = [ { dom: domStandalone(`
content
`), locator: 'div' }, { dom: domInButton(`
content
`), locator: 'div' },