From 5d49c5d612b0ab95df71702116798d728eec9111 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 12 May 2020 16:15:14 -0700 Subject: [PATCH] docs: refer to "working with selectors" from all `'selector'` arguments (#2213) The "working with selectors" section elaborates on rules that we use to parse selectors. Fixes #2197 --- docs/api.md | 84 ++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/api.md b/docs/api.md index 9301b37603f27..305242e268173 100644 --- a/docs/api.md +++ b/docs/api.md @@ -842,28 +842,28 @@ Emitted when a [response] is received. Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the page. #### page.$(selector) -- `selector` <[string]> A selector to query page for +- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. - returns: <[Promise]> -The method finds an element matching the specified selector within the page. See [Working with selectors](#working-with-selectors) for more details. If no elements match the selector, the return value resolves to `null`. +The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`. Shortcut for [page.mainFrame().$(selector)](#frameselector). #### page.$$(selector) -- `selector` <[string]> A selector to query page for +- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. - returns: <[Promise]<[Array]<[ElementHandle]>>> -The method finds all elements matching the specified selector within the page. See [Working with selectors](#working-with-selectors) for more details. If no elements match the selector, the return value resolves to `[]`. +The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). #### page.$eval(selector, pageFunction[, arg]) -- `selector` <[string]> A selector to query page for +- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. - `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context - `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` -The method finds an element matching the specified selector within the page and passes it as a first argument to `pageFunction`. See [Working with selectors](#working-with-selectors) for more details. If no elements match the selector, the method throws an error. +The method finds an element matching the specified selector within the page and passes it as a first argument to `pageFunction`. If no elements match the selector, the method throws an error. If `pageFunction` returns a [Promise], then `page.$eval` would wait for the promise to resolve and return its value. @@ -877,12 +877,12 @@ const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + su Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-arg). #### page.$$eval(selector, pageFunction[, arg]) -- `selector` <[string]> A selector to query page for +- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. - `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context - `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` -The method finds all elements matching the specified selector within the page and passes an array of matched elements as a first argument to `pageFunction`. See [Working with selectors](#working-with-selectors) for more details. +The method finds all elements matching the specified selector within the page and passes an array of matched elements as a first argument to `pageFunction`. If `pageFunction` returns a [Promise], then `page.$$eval` would wait for the promise to resolve and return its value. @@ -944,7 +944,7 @@ Adds a `` tag into the page with the desired url or a ` A selector to search for checkbox or radio button to check. If there are multiple elements satisfying the selector, the first will be checked. +- `selector` <[string]> A selector to search for checkbox or radio button to check. If there are multiple elements satisfying the selector, the first will be checked. See [working with selectors](#working-with-selectors) for more details. - `options` <[Object]> - `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is: - displayed: has non-empty bounding box and no `visibility:hidden` (note that elements of zero size or with `display:none` are considered not displayed), @@ -961,7 +961,7 @@ If there's no element matching `selector`, the method waits until a matching ele Shortcut for [page.mainFrame().check(selector[, options])](#framecheckselector-options). #### page.click(selector[, options]) -- `selector` <[string]> A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. +- `selector` <[string]> A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See [working with selectors](#working-with-selectors) for more details. - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `clickCount` <[number]> defaults to 1. See [UIEvent.detail]. @@ -1015,7 +1015,7 @@ Get the browser context that the page belongs to. Browser-specific Coverage implementation, only available for Chromium atm. See [ChromiumCoverage](#class-chromiumcoverage) for more details. #### page.dblclick(selector[, options]) -- `selector` <[string]> A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. +- `selector` <[string]> A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. See [working with selectors](#working-with-selectors) for more details. - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. @@ -1043,7 +1043,7 @@ Shortcut for [page.mainFrame().dblclick(selector[, options])](#framedblclicksele #### page.dispatchEvent(selector, type[, eventInit, options]) -- `selector` <[string]> A selector to search for element to use. If there are multiple elements satisfying the selector, the first will be used. +- `selector` <[string]> A selector to search for element to use. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](#working-with-selectors) for more details. - `type` <[string]> DOM event type: `"click"`, `"dragstart"`, etc. - `eventInit` <[Object]> event-specific initialization properties. - `options` <[Object]> @@ -1231,7 +1231,7 @@ const fs = require('fs'); ``` #### page.fill(selector, value[, options]) -- `selector` <[string]> A selector to query page for. +- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. - `value` <[string]> Value to fill for the ``, `