Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: call `focus()` twice to workaround firefox not focusing element (#23535)

Andrey Lushnikov3a00fc4edf1c
diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts
index 3b2703e51a..99caa7f40d 100644
--- a/packages/playwright-core/src/server/injected/injectedScript.ts
+++ b/packages/playwright-core/src/server/injected/injectedScript.ts
@@ -793,6 +793,9 @@ export class InjectedScript {
// contenteditable to the new element. However, blurring the previous one helps.
(activeElement as HTMLElement | SVGElement).blur();
}
+ // On firefox, we have to call focus() twice to actually focus an element in certain
+ // scenarios.
+ (node as HTMLElement | SVGElement).focus();
(node as HTMLElement | SVGElement).focus();
if (resetSelectionIfNotFocused && !wasFocused && node.nodeName.toLowerCase() === 'input') {