From fc5898892ba4189f8b05e267b1bd7b25aadc8eb9 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 4 Dec 2019 13:11:10 -0800 Subject: [PATCH] feat(selectors): support optional "visible" property in all selectors (#129) --- docs/api.md | 125 +++++++++++----- src/chromium/Page.ts | 26 ++-- src/dom.ts | 150 ++++++++++---------- src/firefox/Page.ts | 28 ++-- src/frames.ts | 68 ++++----- src/injected/injected.ts | 10 ++ src/types.ts | 25 +++- src/webkit/Launcher.ts | 2 +- src/webkit/Page.ts | 26 ++-- test/click.spec.js | 26 ++++ test/page.spec.js | 21 +++ test/queryselector.spec.js | 54 ++++++- test/waittask.spec.js | 26 ++-- utils/doclint/check_public_api/JSBuilder.js | 9 ++ utils/doclint/check_public_api/index.js | 4 +- utils/protocol-types-generator/index.js | 6 +- 16 files changed, 397 insertions(+), 209 deletions(-) diff --git a/docs/api.md b/docs/api.md index b9b837d2e1..c6682e0044 100644 --- a/docs/api.md +++ b/docs/api.md @@ -310,6 +310,9 @@ * [coverage.stopCSSCoverage()](#coveragestopcsscoverage) * [coverage.stopJSCoverage()](#coveragestopjscoverage) - [class: TimeoutError](#class-timeouterror) +- [class: Selector](#class-selector) + * [selector.selector](#selectorselector) + * [selector.visible](#selectorvisible) ### Overview @@ -1049,7 +1052,7 @@ Emitted when a request finishes successfully. Emitted when a [response] is received. #### page.$(selector) -- `selector` <[string]> A [selector] to query page for +- `selector` <[string]|[Selector]> A [selector] to query page for - returns: <[Promise]> The method runs `document.querySelector` within the page. If no element matches the selector, the return value resolves to `null`. @@ -1057,7 +1060,7 @@ The method runs `document.querySelector` within the page. If no element matches Shortcut for [page.mainFrame().$(selector)](#frameselector). #### page.$$(selector) -- `selector` <[string]> A [selector] to query page for +- `selector` <[string]|[Selector]> A [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 resolves to `[]`. @@ -1065,7 +1068,7 @@ The method runs `document.querySelectorAll` within the page. If no elements matc Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). #### page.$$eval(selector, pageFunction[, ...args]) -- `selector` <[string]> A [selector] to query page for +- `selector` <[string]|[Selector]> A [selector] to query page for - `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context - `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` @@ -1080,7 +1083,7 @@ const divsCounts = await page.$$eval('div', divs => divs.length); ``` #### page.$eval(selector, pageFunction[, ...args]) -- `selector` <[string]> A [selector] to query page for +- `selector` <[string]|[Selector]> A [selector] to query page for - `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context - `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` @@ -1145,7 +1148,7 @@ Get the browser the page belongs to. Get the browser context that the page belongs to. #### 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]|[Selector]> A [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `clickCount` <[number]> defaults to 1. See [UIEvent.detail]. @@ -1192,7 +1195,7 @@ Gets the full HTML contents of the page, including the doctype. - returns: <[Coverage]> #### 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]|[Selector]> A [selector] to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. @@ -1431,7 +1434,7 @@ const fs = require('fs'); ``` #### page.fill(selector, value) -- `selector` <[string]> A [selector] to query page for. +- `selector` <[string]|[Selector]> A [selector] to query page for. - `value` <[string]> Value to fill for the ``, `