feat(element-handle): remove throw in case of empty elementHandle (#2740)

Fixes #2708
This commit is contained in:
Yaniv Efraim 2018-06-15 00:28:52 +03:00 committed by Andrey Lushnikov
parent 38f112f395
commit 9a650c818d
2 changed files with 4 additions and 5 deletions

View File

@ -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();

View File

@ -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 = '<div class="a">not-a-child-div</div><div id="myId"></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() {