From af89e893e7e5384f593be968e610f15c1595cb82 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 15 Aug 2017 14:54:02 -0700 Subject: [PATCH] Implement basic element handles (#248) This patch implements basic element handles which a backed with remote objects. Fixes #111 --- docs/api.md | 102 +++++++++++++++++++----- lib/Connection.js | 3 + lib/ElementHandle.js | 98 +++++++++++++++++++++++ lib/FrameManager.js | 81 ++++++------------- lib/Page.js | 23 +++++- test/test.js | 72 +++++++++++++++++ utils/doclint/check_public_api/index.js | 1 + 7 files changed, 299 insertions(+), 81 deletions(-) create mode 100644 lib/ElementHandle.js diff --git a/docs/api.md b/docs/api.md index 32d2fbd001d..f75a91001ea 100644 --- a/docs/api.md +++ b/docs/api.md @@ -26,6 +26,7 @@ + [event: 'requestfailed'](#event-requestfailed) + [event: 'requestfinished'](#event-requestfinished) + [event: 'response'](#event-response) + + [page.$(selector)](#pageselector) + [page.addBinding(name, puppeteerFunction)](#pageaddbindingname-puppeteerfunction) + [page.addScriptTag(url)](#pageaddscripttagurl) + [page.click(selector[, options])](#pageclickselector-options) @@ -82,12 +83,10 @@ + [dialog.message()](#dialogmessage) + [dialog.type](#dialogtype) * [class: Frame](#class-frame) + + [frame.$(selector)](#frameselector) + [frame.addScriptTag(url)](#frameaddscripttagurl) + [frame.childFrames()](#framechildframes) - + [frame.click(selector[, options])](#frameclickselector-options) + [frame.evaluate(pageFunction, ...args)](#frameevaluatepagefunction-args) - + [frame.focus(selector)](#framefocusselector) - + [frame.hover(selector)](#framehoverselector) + [frame.injectFile(filePath)](#frameinjectfilefilepath) + [frame.isDetached()](#frameisdetached) + [frame.name()](#framename) @@ -98,6 +97,11 @@ + [frame.waitFor(selectorOrFunctionOrTimeout[, options])](#framewaitforselectororfunctionortimeout-options) + [frame.waitForFunction(pageFunction[, options, ...args])](#framewaitforfunctionpagefunction-options-args) + [frame.waitForSelector(selector[, options])](#framewaitforselectorselector-options) + * [class: ElementHandle](#class-elementhandle) + + [elementHandle.click([options])](#elementhandleclickoptions) + + [elementHandle.evaluate(pageFunction, ...args)](#elementhandleevaluatepagefunction-args) + + [elementHandle.hover()](#elementhandlehover) + + [elementHandle.release()](#elementhandlerelease) * [class: Request](#class-request) + [request.abort()](#requestabort) + [request.continue([overrides])](#requestcontinueoverrides) @@ -283,6 +287,13 @@ Emitted when a request is successfully finished. Emitted when a [response] is received. +#### page.$(selector) +- `selector` <[string]> Selector to query page for +- returns: <[Promise]<[ElementHandle]>> Promise which resolves to ElementHandle pointing to the page element. + +The method queries page for the selector. If there's no such element on the page, the method will resolve to `null`. + +Shortcut for [page.mainFrame().$(selector)](#frameselector). #### page.addBinding(name, puppeteerFunction) - `name` <[string]> Name of the binding on window object @@ -345,7 +356,6 @@ puppeteer.launch().then(async browser => { ``` - #### page.addScriptTag(url) - `url` <[string]> Url of a script to be added - returns: <[Promise]> Promise which resolves as the script gets added and loads. @@ -932,6 +942,12 @@ puppeteer.launch().then(async browser => { }); ``` +#### frame.$(selector) +- `selector` <[string]> Selector to query page for +- returns: <[Promise]<[ElementHandle]>> Promise which resolves to ElementHandle pointing to the page element. + +The method queries page for the selector. If there's no such element on the page, the method will resolve to `null`. + #### frame.addScriptTag(url) - `url` <[string]> Url of a script to be added @@ -942,14 +958,6 @@ Adds a `