mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Implement page.$$ method (#463)
This patch implements page.$$ which runs document.querySelectorAll in page and returns results as an array of ElementHandle instances. Fixes #384.
This commit is contained in:
14
test/test.js
14
test/test.js
@@ -1074,6 +1074,20 @@ describe('Page', function() {
|
||||
expect(element).toBe(null);
|
||||
}));
|
||||
});
|
||||
describe('Page.$$', function() {
|
||||
it('should query existing elements', SX(async function() {
|
||||
await page.setContent('<div>A</div><br/><div>B</div>');
|
||||
const elements = await page.$$('div');
|
||||
expect(elements.length).toBe(2);
|
||||
const promises = elements.map(element => element.evaluate(e => e.textContent));
|
||||
expect(await Promise.all(promises)).toEqual(['A', 'B']);
|
||||
}));
|
||||
it('should return ampty array if nothing is found', SX(async function() {
|
||||
await page.goto(EMPTY_PAGE);
|
||||
const elements = await page.$$('div');
|
||||
expect(elements.length).toBe(0);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ElementHandle.evaluate', function() {
|
||||
it('should work', SX(async function() {
|
||||
|
||||
Reference in New Issue
Block a user