diff --git a/lib/ElementHandle.js b/lib/ElementHandle.js index 5bba6af281b..9a07e63ff12 100644 --- a/lib/ElementHandle.js +++ b/lib/ElementHandle.js @@ -306,8 +306,6 @@ class ElementHandle extends JSHandle { (element, selector) => Array.from(element.querySelectorAll(selector)), this, selector ); - if (!(await arrayHandle.jsonValue()).length) - throw new Error(`Error: failed to find elements matching selector "${selector}"`); const result = await this.executionContext().evaluate(pageFunction, arrayHandle, ...args); await arrayHandle.dispose(); diff --git a/test/elementhandle.spec.js b/test/elementhandle.spec.js index aee915ed7a8..090e620e6ed 100644 --- a/test/elementhandle.spec.js +++ b/test/elementhandle.spec.js @@ -337,13 +337,14 @@ module.exports.addTests = function({testRunner, expect}) { expect(content).toEqual(['a1-child-div', 'a2-child-div']); }); - it('should throw in case of missing selector', async({page, server}) => { + it('should not throw in case of missing selector', async({page, server}) => { const htmlContent = '
not-a-child-div
'; await page.setContent(htmlContent); const elementHandle = await page.$('#myId'); - const errorMessage = await elementHandle.$$eval('.a', nodes => nodes.map(n => n.innerText)).catch(error => error.message); - expect(errorMessage).toBe(`Error: failed to find elements matching selector ".a"`); + const nodesLength = await elementHandle.$$eval('.a', nodes => nodes.length); + expect(nodesLength).toBe(0); }); + }); describe('ElementHandle.$$', function() {