mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
api(waitFor): click(waitFor) -> click(force) (#1275)
This commit is contained in:
parent
578880cb8b
commit
3c35d7b058
118
docs/api.md
118
docs/api.md
@ -913,7 +913,11 @@ Shortcut for [page.mainFrame().addStyleTag(options)](#frameaddstyletagoptions).
|
||||
#### page.check(selector, [options])
|
||||
- `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.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -939,7 +943,11 @@ Shortcut for [page.mainFrame().check(selector[, options])](#framecheckselector-o
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -994,7 +1002,11 @@ Browser-specific Coverage implementation, only available for Chromium atm. See [
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1173,7 +1185,6 @@ const fs = require('fs');
|
||||
- `selector` <[string]> A selector to query page for.
|
||||
- `value` <[string]> Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1194,7 +1205,6 @@ Shortcut for [page.mainFrame().fill()](#framefillselector-value)
|
||||
#### page.focus(selector[, options])
|
||||
- `selector` <[string]> A selector of an element to focus. If there are multiple elements satisfying the selector, the first will be focused.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully focused. The promise will be rejected if there is no element matching `selector`.
|
||||
|
||||
@ -1285,7 +1295,11 @@ Shortcut for [page.mainFrame().goto(url[, options])](#framegotourl-options)
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`.
|
||||
|
||||
@ -1391,7 +1405,6 @@ The `format` options are:
|
||||
- `options` <[Object]>
|
||||
- `text` <[string]> If specified, generates an input event with this text.
|
||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1472,7 +1485,6 @@ await browser.close();
|
||||
- `label` <[string]> Matches by `option.label`.
|
||||
- `index` <[number]> Matches by the index.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1576,7 +1588,11 @@ Shortcut for [page.mainFrame().title()](#frametitle).
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1601,7 +1617,6 @@ Shortcut for [page.mainFrame().tripleclick(selector[, options])](#frametriplecli
|
||||
- `text` <[string]> A text to type into a focused element.
|
||||
- `options` <[Object]>
|
||||
- `delay` <[number]> Time to wait between key presses in milliseconds. Defaults to 0.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1626,7 +1641,11 @@ Shortcut for [page.mainFrame().type(selector, text[, options])](#frametypeselect
|
||||
#### page.uncheck(selector, [options])
|
||||
- `selector` <[string]> A selector to search for uncheckbox to check. If there are multiple elements satisfying the selector, the first will be checked.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -1987,7 +2006,11 @@ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<s
|
||||
#### frame.check(selector, [options])
|
||||
- `selector` <[string]> A selector to search for checkbox to check. If there are multiple elements satisfying the selector, the first will be checked.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2014,7 +2037,11 @@ If there's no element matching `selector`, the method throws an error.
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2042,7 +2069,11 @@ Gets the full HTML contents of the frame, including the doctype.
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2121,7 +2152,6 @@ await resultHandle.dispose();
|
||||
- `selector` <[string]> A selector to query page for.
|
||||
- `value` <[string]> Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2138,7 +2168,6 @@ If there's no text `<input>`, `<textarea>` or `[contenteditable]` element matchi
|
||||
#### frame.focus(selector[, options])
|
||||
- `selector` <[string]> A selector of an element to focus. If there are multiple elements satisfying the selector, the first will be focused.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully focused. The promise will be rejected if there is no element matching `selector`.
|
||||
|
||||
@ -2192,7 +2221,11 @@ console.log(frame === contentFrame); // -> true
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`.
|
||||
|
||||
@ -2222,7 +2255,6 @@ If the name is empty, returns the id attribute instead.
|
||||
- `options` <[Object]>
|
||||
- `text` <[string]> If specified, generates an input event with this text.
|
||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2246,7 +2278,6 @@ If `key` is a single character and no modifier keys besides `Shift` are being he
|
||||
- `label` <[string]> Matches by `option.label`.
|
||||
- `index` <[number]> Matches by the index.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2298,7 +2329,11 @@ frame.select('select#colors', { value: 'blue' }, { index: 2 }, 'red');
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2321,7 +2356,6 @@ Bear in mind that if the first or second click of the `tripleclick()` triggers a
|
||||
- `text` <[string]> A text to type into a focused element.
|
||||
- `options` <[Object]>
|
||||
- `delay` <[number]> Time to wait between key presses in milliseconds. Defaults to 0.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom. Defaults to `true`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2344,7 +2378,11 @@ await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a
|
||||
#### frame.uncheck(selector, [options])
|
||||
- `selector` <[string]> A selector to search for uncheckbox to check. If there are multiple elements satisfying the selector, the first will be checked.
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to be present in the dom and displayed (for example, no `display:none`), stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2615,7 +2653,11 @@ This method returns the bounding box of the element (relative to the main frame)
|
||||
|
||||
#### elementHandle.check([options])
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2637,7 +2679,11 @@ If element is not already checked, it scrolls it into view if needed, and then u
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2662,7 +2708,11 @@ If the element is detached from DOM, the method throws an error.
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2707,7 +2757,11 @@ Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the hover, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- returns: <[Promise]> Promise which resolves when the element is successfully hovered.
|
||||
|
||||
@ -2812,7 +2866,11 @@ Sets the value of the file input to these file paths or files. If some of the `
|
||||
- x <[number]>
|
||||
- y <[number]>
|
||||
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
@ -2862,7 +2920,11 @@ await elementHandle.press('Enter');
|
||||
|
||||
#### elementHandle.uncheck([options])
|
||||
- `options` <[Object]>
|
||||
- `waitFor` <[boolean]> Whether to wait for the element to stop moving (for example, wait until css transition finishes) and potentially receive pointer events at the click point (for example, wait until element becomes non-obscured by other elements). Defaults to `true`.
|
||||
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
|
||||
- displayed (for example, no `display:none`),
|
||||
- is not moving (for example, waits until css transition finishes),
|
||||
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
|
||||
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
|
||||
- `waitUntil` <"commit"|"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to `commit` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
|
||||
- `'commit'` - navigation is committed, new url is displayed in the browser address bar.
|
||||
- `'load'` - consider navigation to be finished when the `load` event is fired.
|
||||
|
32
src/dom.ts
32
src/dom.ts
@ -241,16 +241,14 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||
return point;
|
||||
}
|
||||
|
||||
async _performPointerAction(action: (point: types.Point) => Promise<void>, options?: PointerActionOptions & types.ActionWaitOptions): Promise<void> {
|
||||
const { waitFor = true } = (options || {});
|
||||
if (!helper.isBoolean(waitFor))
|
||||
throw new Error('waitFor option should be a boolean, got "' + (typeof waitFor) + '"');
|
||||
if (waitFor)
|
||||
async _performPointerAction(action: (point: types.Point) => Promise<void>, options?: PointerActionOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions): Promise<void> {
|
||||
const { force = false } = (options || {});
|
||||
if (!force)
|
||||
await this._waitForDisplayedAtStablePosition(options);
|
||||
const offset = options ? options.offset : undefined;
|
||||
await this._scrollRectIntoViewIfNeeded(offset ? { x: offset.x, y: offset.y, width: 0, height: 0 } : undefined);
|
||||
const point = offset ? await this._offsetPoint(offset) : await this._clickablePoint();
|
||||
if (waitFor)
|
||||
if (!force)
|
||||
await this._waitForHitTargetAt(point, options);
|
||||
|
||||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
||||
@ -263,23 +261,23 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||
}, options);
|
||||
}
|
||||
|
||||
hover(options?: PointerActionOptions & types.ActionWaitOptionsNoNavigation): Promise<void> {
|
||||
hover(options?: PointerActionOptions & types.PointerActionWaitOptions): Promise<void> {
|
||||
return this._performPointerAction(point => this._page.mouse.move(point.x, point.y), options);
|
||||
}
|
||||
|
||||
click(options?: ClickOptions & types.ActionWaitOptions): Promise<void> {
|
||||
click(options?: ClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions): Promise<void> {
|
||||
return this._performPointerAction(point => this._page.mouse.click(point.x, point.y, options), options);
|
||||
}
|
||||
|
||||
dblclick(options?: MultiClickOptions & types.ActionWaitOptions): Promise<void> {
|
||||
dblclick(options?: MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions): Promise<void> {
|
||||
return this._performPointerAction(point => this._page.mouse.dblclick(point.x, point.y, options), options);
|
||||
}
|
||||
|
||||
tripleclick(options?: MultiClickOptions & types.ActionWaitOptions): Promise<void> {
|
||||
tripleclick(options?: MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions): Promise<void> {
|
||||
return this._performPointerAction(point => this._page.mouse.tripleclick(point.x, point.y, options), options);
|
||||
}
|
||||
|
||||
async select(values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[], options?: types.ActionWaitOptionsNoWaitFor): Promise<string[]> {
|
||||
async select(values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[], options?: types.NavigatingActionWaitOptions): Promise<string[]> {
|
||||
let vals: string[] | ElementHandle[] | types.SelectOption[];
|
||||
if (!Array.isArray(values))
|
||||
vals = [ values ] as (string[] | ElementHandle[] | types.SelectOption[]);
|
||||
@ -301,7 +299,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||
}, options);
|
||||
}
|
||||
|
||||
async fill(value: string, options?: types.ActionWaitOptionsNoWaitFor): Promise<void> {
|
||||
async fill(value: string, options?: types.NavigatingActionWaitOptions): Promise<void> {
|
||||
assert(helper.isString(value), 'Value must be string. Found value "' + value + '" of type "' + (typeof value) + '"');
|
||||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
||||
const error = await this._evaluateInUtility((injected, node, value) => injected.fill(node, value), value);
|
||||
@ -356,29 +354,29 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
async type(text: string, options?: { delay?: number } & types.ActionWaitOptionsNoWaitFor) {
|
||||
async type(text: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
||||
await this.focus();
|
||||
await this._page.keyboard.type(text, options);
|
||||
}, options);
|
||||
}
|
||||
|
||||
async press(key: string, options?: { delay?: number, text?: string } & types.ActionWaitOptionsNoWaitFor) {
|
||||
async press(key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
||||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
||||
await this.focus();
|
||||
await this._page.keyboard.press(key, options);
|
||||
}, options);
|
||||
}
|
||||
|
||||
async check(options?: types.ActionWaitOptions) {
|
||||
async check(options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
await this._setChecked(true, options);
|
||||
}
|
||||
|
||||
async uncheck(options?: types.ActionWaitOptions) {
|
||||
async uncheck(options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
await this._setChecked(false, options);
|
||||
}
|
||||
|
||||
private async _setChecked(state: boolean, options?: types.ActionWaitOptions) {
|
||||
private async _setChecked(state: boolean, options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
if (await this._evaluateInUtility((injected, node) => injected.isCheckboxChecked(node)) === state)
|
||||
return;
|
||||
await this.click(options);
|
||||
|
@ -100,7 +100,7 @@ export class FrameManager {
|
||||
}
|
||||
}
|
||||
|
||||
async waitForNavigationsCreatedBy<T>(action: () => Promise<T>, options?: types.ActionWaitOptionsNoWaitFor): Promise<T> {
|
||||
async waitForNavigationsCreatedBy<T>(action: () => Promise<T>, options?: types.NavigatingActionWaitOptions): Promise<T> {
|
||||
if (options && options.waitUntil === 'nowait')
|
||||
return action();
|
||||
const barrier = new PendingNavigationBarrier(options);
|
||||
@ -583,10 +583,20 @@ export class Frame {
|
||||
async waitForSelector(selector: string, options?: types.WaitForElementOptions): Promise<dom.ElementHandle<Element> | null> {
|
||||
if (options && (options as any).visibility)
|
||||
throw new Error('options.visibility is not supported, did you mean options.waitFor?');
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
const { timeout = this._page._timeoutSettings.timeout(), waitFor = 'attached' } = (options || {});
|
||||
if (!['attached', 'detached', 'visible', 'hidden'].includes(waitFor))
|
||||
throw new Error(`Unsupported waitFor option "${waitFor}"`);
|
||||
|
||||
const task = dom.waitForSelectorTask(selector, waitFor, timeout);
|
||||
const result = await this._scheduleRerunnableTask(task, 'utility', timeout, `selector "${selectorToString(selector, waitFor)}"`);
|
||||
if (!result.asElement()) {
|
||||
result.dispose();
|
||||
return null;
|
||||
}
|
||||
const handle = result.asElement() as dom.ElementHandle<Element>;
|
||||
const mainContext = await this._mainContext();
|
||||
if (handle && handle._context !== mainContext) {
|
||||
const adopted = this._page._delegate.adoptElementHandle(handle, mainContext);
|
||||
const adopted = await this._page._delegate.adoptElementHandle(handle, mainContext);
|
||||
handle.dispose();
|
||||
return adopted;
|
||||
}
|
||||
@ -801,69 +811,69 @@ export class Frame {
|
||||
return result!;
|
||||
}
|
||||
|
||||
async click(selector: string, options?: dom.ClickOptions & types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async click(selector: string, options?: dom.ClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.click(options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async dblclick(selector: string, options?: dom.MultiClickOptions & types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async dblclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.dblclick(options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.tripleclick(options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async fill(selector: string, value: string, options?: types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async fill(selector: string, value: string, options?: types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.fill(value, options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async focus(selector: string, options?: types.ActionWaitOptionsNoNavigation) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async focus(selector: string, options?: types.TimeoutOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.focus();
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async hover(selector: string, options?: dom.PointerActionOptions & types.ActionWaitOptionsNoNavigation) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async hover(selector: string, options?: dom.PointerActionOptions & types.PointerActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.hover(options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.ActionWaitOptions): Promise<string[]> {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.NavigatingActionWaitOptions): Promise<string[]> {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
const result = await handle.select(values, options);
|
||||
handle.dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
async type(selector: string, text: string, options?: { delay?: number } & types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async type(selector: string, text: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.type(text, options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.press(key, options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async check(selector: string, options?: types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async check(selector: string, options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.check(options);
|
||||
handle.dispose();
|
||||
}
|
||||
|
||||
async uncheck(selector: string, options?: types.ActionWaitOptions) {
|
||||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
|
||||
async uncheck(selector: string, options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||
await handle.uncheck(options);
|
||||
handle.dispose();
|
||||
}
|
||||
@ -878,35 +888,10 @@ export class Frame {
|
||||
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrFunctionOrTimeout)));
|
||||
}
|
||||
|
||||
private async _optionallyWaitForSelectorInUtilityContext(selector: string, options: types.ActionWaitOptions | undefined): Promise<dom.ElementHandle<Element>> {
|
||||
const { timeout = this._page._timeoutSettings.timeout(), waitFor = true } = (options || {});
|
||||
if (!helper.isBoolean(waitFor))
|
||||
throw new Error('waitFor option should be a boolean, got "' + (typeof waitFor) + '"');
|
||||
let handle: dom.ElementHandle<Element>;
|
||||
if (waitFor) {
|
||||
const maybeHandle = await this._waitForSelectorInUtilityContext(selector, { timeout, waitFor: 'attached' });
|
||||
if (!maybeHandle)
|
||||
throw new Error('No node found for selector: ' + selectorToString(selector, 'attached'));
|
||||
handle = maybeHandle;
|
||||
} else {
|
||||
const context = await this._context('utility');
|
||||
const maybeHandle = await context._$(selector);
|
||||
assert(maybeHandle, 'No node found for selector: ' + selector);
|
||||
handle = maybeHandle;
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
private async _waitForSelectorInUtilityContext(selector: string, options?: types.WaitForElementOptions): Promise<dom.ElementHandle<Element> | null> {
|
||||
private async _waitForSelectorInUtilityContext(selector: string, options?: types.WaitForElementOptions): Promise<dom.ElementHandle<Element>> {
|
||||
const { timeout = this._page._timeoutSettings.timeout(), waitFor = 'attached' } = (options || {});
|
||||
if (!['attached', 'detached', 'visible', 'hidden'].includes(waitFor))
|
||||
throw new Error(`Unsupported waitFor option "${waitFor}"`);
|
||||
const task = dom.waitForSelectorTask(selector, waitFor, timeout);
|
||||
const result = await this._scheduleRerunnableTask(task, 'utility', timeout, `selector "${selectorToString(selector, waitFor)}"`);
|
||||
if (!result.asElement()) {
|
||||
result.dispose();
|
||||
return null;
|
||||
}
|
||||
return result.asElement() as dom.ElementHandle<Element>;
|
||||
}
|
||||
|
||||
@ -1099,12 +1084,12 @@ function selectorToString(selector: string, waitFor: 'attached' | 'detached' | '
|
||||
|
||||
class PendingNavigationBarrier {
|
||||
private _frameIds = new Map<string, number>();
|
||||
private _options: types.ActionWaitOptionsNoWaitFor | undefined;
|
||||
private _options: types.NavigatingActionWaitOptions | undefined;
|
||||
private _protectCount = 0;
|
||||
private _promise: Promise<void>;
|
||||
private _promiseCallback = () => {};
|
||||
|
||||
constructor(options: types.ActionWaitOptionsNoWaitFor | undefined) {
|
||||
constructor(options: types.NavigatingActionWaitOptions | undefined) {
|
||||
this._options = options;
|
||||
this._promise = new Promise(f => this._promiseCallback = f);
|
||||
this.retain();
|
||||
|
22
src/page.ts
22
src/page.ts
@ -433,47 +433,47 @@ export class Page extends platform.EventEmitter {
|
||||
return this._closed;
|
||||
}
|
||||
|
||||
async click(selector: string, options?: dom.ClickOptions & types.ActionWaitOptions) {
|
||||
async click(selector: string, options?: dom.ClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().click(selector, options);
|
||||
}
|
||||
|
||||
async dblclick(selector: string, options?: dom.MultiClickOptions & types.ActionWaitOptions) {
|
||||
async dblclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().dblclick(selector, options);
|
||||
}
|
||||
|
||||
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.ActionWaitOptions) {
|
||||
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().tripleclick(selector, options);
|
||||
}
|
||||
|
||||
async fill(selector: string, value: string, options?: types.ActionWaitOptions) {
|
||||
async fill(selector: string, value: string, options?: types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().fill(selector, value, options);
|
||||
}
|
||||
|
||||
async focus(selector: string, options?: types.ActionWaitOptionsNoNavigation) {
|
||||
async focus(selector: string, options?: types.TimeoutOptions) {
|
||||
return this.mainFrame().focus(selector, options);
|
||||
}
|
||||
|
||||
async hover(selector: string, options?: dom.PointerActionOptions & types.ActionWaitOptionsNoNavigation) {
|
||||
async hover(selector: string, options?: dom.PointerActionOptions & types.PointerActionWaitOptions) {
|
||||
return this.mainFrame().hover(selector, options);
|
||||
}
|
||||
|
||||
async select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.ActionWaitOptions): Promise<string[]> {
|
||||
async select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.NavigatingActionWaitOptions): Promise<string[]> {
|
||||
return this.mainFrame().select(selector, values, options);
|
||||
}
|
||||
|
||||
async type(selector: string, text: string, options?: { delay?: number } & types.ActionWaitOptions) {
|
||||
async type(selector: string, text: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().type(selector, text, options);
|
||||
}
|
||||
|
||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.ActionWaitOptions) {
|
||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().press(selector, key, options);
|
||||
}
|
||||
|
||||
async check(selector: string, options?: types.ActionWaitOptions) {
|
||||
async check(selector: string, options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().check(selector, options);
|
||||
}
|
||||
|
||||
async uncheck(selector: string, options?: types.ActionWaitOptions) {
|
||||
async uncheck(selector: string, options?: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
|
||||
return this.mainFrame().uncheck(selector, options);
|
||||
}
|
||||
|
||||
|
@ -51,16 +51,14 @@ export type NavigateOptions = TimeoutOptions & {
|
||||
waitUntil?: LifecycleEvent,
|
||||
};
|
||||
|
||||
export type ActionWaitOptionsNoWaitFor = TimeoutOptions & {
|
||||
export type NavigatingActionWaitOptions = TimeoutOptions & {
|
||||
waitUntil?: LifecycleEvent | 'nowait',
|
||||
};
|
||||
|
||||
export type ActionWaitOptionsNoNavigation = TimeoutOptions & {
|
||||
waitFor?: boolean,
|
||||
export type PointerActionWaitOptions = TimeoutOptions & {
|
||||
force?: boolean,
|
||||
};
|
||||
|
||||
export type ActionWaitOptions = ActionWaitOptionsNoWaitFor & ActionWaitOptionsNoNavigation;
|
||||
|
||||
export type WaitForNavigationOptions = TimeoutOptions & {
|
||||
waitUntil?: LifecycleEvent,
|
||||
url?: URLMatch
|
||||
|
@ -149,15 +149,10 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
||||
let error = null;
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
await page.$eval('button', b => b.style.display = 'none');
|
||||
await page.click('button', { waitFor: false }).catch(e => error = e);
|
||||
await page.click('button', { force: true }).catch(e => error = e);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
expect(await page.evaluate(() => result)).toBe('Was not clicked');
|
||||
});
|
||||
it('should throw for non-boolean waitFor', async({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const error = await page.click('button', { waitFor: 'visible' }).catch(e => e);
|
||||
expect(error.message).toBe('waitFor option should be a boolean, got "string"');
|
||||
});
|
||||
it('should waitFor visible', async({page, server}) => {
|
||||
let done = false;
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
@ -233,13 +228,6 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
||||
await page.click('label[for="agree"]');
|
||||
expect(await page.evaluate(() => result.check)).toBe(false);
|
||||
});
|
||||
|
||||
it('should fail to click a missing button', async({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
let error = null;
|
||||
await page.click('button.does-not-exist', { waitFor: false }).catch(e => error = e);
|
||||
expect(error.message).toBe('No node found for selector: button.does-not-exist');
|
||||
});
|
||||
it.skip(FFOX)('should not hang with touch-enabled viewports', async({server, browser}) => {
|
||||
// @see https://github.com/GoogleChrome/puppeteer/issues/161
|
||||
const context = await browser.newContext({ viewport: playwright.devices['iPhone 6'].viewport });
|
||||
@ -490,7 +478,7 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
||||
blocker.style.top = '0';
|
||||
document.body.appendChild(blocker);
|
||||
});
|
||||
await button.click({ waitFor: false });
|
||||
await button.click({ force: true });
|
||||
expect(await page.evaluate(() => window.result)).toBe('Was not clicked');
|
||||
});
|
||||
|
||||
|
@ -264,20 +264,20 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const button = await page.$('button');
|
||||
await page.evaluate(button => button.style.display = 'none', button);
|
||||
const error = await button.click({ waitFor: false }).catch(err => err);
|
||||
const error = await button.click({ force: true }).catch(err => err);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
it('should throw for recursively hidden nodes', async({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const button = await page.$('button');
|
||||
await page.evaluate(button => button.parentElement.style.display = 'none', button);
|
||||
const error = await button.click({ waitFor: false }).catch(err => err);
|
||||
const error = await button.click({ force: true }).catch(err => err);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
it('should throw for <br> elements', async({page, server}) => {
|
||||
await page.setContent('hello<br>goodbye');
|
||||
const br = await page.$('br');
|
||||
const error = await br.click({ waitFor: false }).catch(err => err);
|
||||
const error = await br.click({ force: true }).catch(err => err);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
});
|
||||
|
@ -1022,12 +1022,12 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
|
||||
it('should throw on hidden and invisible elements', async({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||
await page.$eval('input', i => i.style.display = 'none');
|
||||
const invisibleError = await page.fill('input', 'some value', { waitFor: false }).catch(e => e);
|
||||
const invisibleError = await page.fill('input', 'some value', { force: true }).catch(e => e);
|
||||
expect(invisibleError.message).toBe('Element is not visible');
|
||||
|
||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||
await page.$eval('input', i => i.style.visibility = 'hidden');
|
||||
const hiddenError = await page.fill('input', 'some value', { waitFor: false }).catch(e => e);
|
||||
const hiddenError = await page.fill('input', 'some value', { force: true }).catch(e => e);
|
||||
expect(hiddenError.message).toBe('Element is hidden');
|
||||
});
|
||||
it('should be able to fill the body', async({page}) => {
|
||||
|
@ -202,6 +202,8 @@ function compareDocumentations(actual, expected) {
|
||||
const expectedName = expected.name.replace(/\ /g, '').replace(/ElementHandle\<Node\>/g, 'ElementHandle');
|
||||
if (expectedName !== actualName)
|
||||
errors.push(`${source} ${actualName} != ${expectedName}`);
|
||||
if (actual.name === 'boolean' || actual.name === 'string')
|
||||
return;
|
||||
const actualPropertiesMap = new Map(actual.properties.map(property => [property.name, property.type]));
|
||||
const expectedPropertiesMap = new Map(expected.properties.map(property => [property.name, property.type]));
|
||||
const propertiesDiff = diff(Array.from(actualPropertiesMap.keys()).sort(), Array.from(expectedPropertiesMap.keys()).sort());
|
||||
|
Loading…
Reference in New Issue
Block a user