From 151d512ae2d652d8bc91db1ebcb635fd24a45d1a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 22 Aug 2017 22:56:55 -0700 Subject: [PATCH] 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. --- docs/api.md | 19 +++++++++++++++++-- lib/FrameManager.js | 25 ++++++++++++++++++++++++- lib/Page.js | 8 ++++++++ test/test.js | 14 ++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 7f45b43b9f8..cd666c89178 100644 --- a/docs/api.md +++ b/docs/api.md @@ -27,6 +27,7 @@ + [event: 'requestfinished'](#event-requestfinished) + [event: 'response'](#event-response) + [page.$(selector)](#pageselector) + + [page.$$(selector)](#pageselector) + [page.addScriptTag(url)](#pageaddscripttagurl) + [page.click(selector[, options])](#pageclickselector-options) + [page.close()](#pageclose) @@ -85,6 +86,7 @@ + [dialog.type](#dialogtype) * [class: Frame](#class-frame) + [frame.$(selector)](#frameselector) + + [frame.$$(selector)](#frameselector) + [frame.addScriptTag(url)](#frameaddscripttagurl) + [frame.childFrames()](#framechildframes) + [frame.evaluate(pageFunction, ...args)](#frameevaluatepagefunction-args) @@ -297,6 +299,14 @@ The method runs `document.querySelector` within the page. If no element matches Shortcut for [page.mainFrame().$(selector)](#frameselector). +#### page.$$(selector) +- `selector` <[string]> Selector to query page for +- returns: <[Promise]<[Array]<[ElementHandle]>>> + +The method runs `document.querySelectorAll` within the page. If no elements match the selector, the return value resolve to `[]`. + +Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). + #### page.addScriptTag(url) - `url` <[string]> Url of the `