diff --git a/lib/ElementHandle.js b/lib/ElementHandle.js index 408afa36..b83e7dbf 100644 --- a/lib/ElementHandle.js +++ b/lib/ElementHandle.js @@ -42,7 +42,7 @@ class ElementHandle extends JSHandle { async _scrollIntoViewIfNeeded() { const error = await this.executionContext().evaluate(element => { - if (!element.ownerDocument.contains(element)) + if (!element.isConnected) return 'Node is detached from document'; if (element.nodeType !== Node.ELEMENT_NODE) return 'Node is not of type HTMLElement'; diff --git a/test/assets/shadow.html b/test/assets/shadow.html new file mode 100644 index 00000000..7242e673 --- /dev/null +++ b/test/assets/shadow.html @@ -0,0 +1,17 @@ + diff --git a/test/test.js b/test/test.js index d6f688ba..3b0bde15 100644 --- a/test/test.js +++ b/test/test.js @@ -1611,6 +1611,12 @@ describe('Page', function() { await button.click(); expect(await page.evaluate(() => result)).toBe('Clicked'); })); + it('should work for Shadow DOM v1', SX(async function() { + await page.goto(PREFIX + '/shadow.html'); + const buttonHandle = await page.evaluateHandle(() => button); + await buttonHandle.click(); + expect(await page.evaluate(() => clicked)).toBe(true); + })); it('should work for TextNodes', SX(async function() { await page.goto(PREFIX + '/input/button.html'); const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);