feat(element-handle): remove throw in case of empty elementHandle (#2740)
Fixes #2708
This commit is contained in:
parent
38f112f395
commit
9a650c818d
@ -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();
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user