Skip to content

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

fix(dom): click on links inside shadow dom (#5850)

Yury Semikhatsky4f2827f302be
diff --git a/src/server/injected/injectedScript.ts b/src/server/injected/injectedScript.ts
index 9b05f56f39..4a640da205 100644
--- a/src/server/injected/injectedScript.ts
+++ b/src/server/injected/injectedScript.ts
@@ -645,7 +645,10 @@ export class InjectedScript {
let container: Document | ShadowRoot | null = document;
let element: Element | undefined;
while (container) {
- const innerElement = container.elementFromPoint(x, y) as Element | undefined;
+ // elementFromPoint works incorrectly in Chromium (http://crbug.com/1188919),
+ // so we use elementsFromPoint instead.
+ const elements = container.elementsFromPoint(x, y);
+ const innerElement = elements[0] as Element | undefined;
if (!innerElement || element === innerElement)
break;
element = innerElement;
diff --git a/test/selectors-misc.spec.ts b/test/selectors-misc.spec.ts
index feaf41419c..f59930f96b 100644
--- a/test/selectors-misc.spec.ts
+++ b/test/selectors-misc.spec.ts
@@ -27,8 +27,8 @@ it('should work for open shadow roots', async ({page, server}) => {
expect(await page.$$(`data-testid:light=foo`)).toEqual([]);
});
-it('should click on links in shadow dom', (test, { browserName }) => {
- test.fixme(browserName === 'chromium', 'Cannot get link quads, see #5765');
+it('should click on links in shadow dom', (test, { browserName, browserChannel }) => {
+ test.fixme(browserName === 'chromium' && !!browserChannel, 'Enable when crrev.com/864024 get to the stable channel');
}, async ({page, server}) => {
await page.goto(server.PREFIX + '/shadow-dom-link.html');
expect(await page.evaluate(() => (window as any).clickCount)).toBe(0);