playwright-ruby-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -15
- data/lib/playwright/channel_owners/browser.rb +2 -2
- data/lib/playwright/channel_owners/console_message.rb +25 -0
- data/lib/playwright/channel_owners/element_handle.rb +8 -0
- data/lib/playwright/channel_owners/js_handle.rb +4 -0
- data/lib/playwright/channel_owners/page.rb +14 -1
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +20 -6
- data/lib/playwright_api/browser.rb +52 -39
- data/lib/playwright_api/browser_context.rb +94 -44
- data/lib/playwright_api/browser_type.rb +72 -53
- data/lib/playwright_api/cdp_session.rb +10 -7
- data/lib/playwright_api/chromium_browser_context.rb +3 -0
- data/lib/playwright_api/console_message.rb +12 -5
- data/lib/playwright_api/dialog.rb +3 -1
- data/lib/playwright_api/download.rb +13 -4
- data/lib/playwright_api/element_handle.rb +226 -113
- data/lib/playwright_api/file_chooser.rb +4 -2
- data/lib/playwright_api/frame.rb +276 -128
- data/lib/playwright_api/js_handle.rb +30 -10
- data/lib/playwright_api/keyboard.rb +56 -18
- data/lib/playwright_api/mouse.rb +6 -3
- data/lib/playwright_api/page.rb +452 -237
- data/lib/playwright_api/playwright.rb +80 -16
- data/lib/playwright_api/request.rb +35 -15
- data/lib/playwright_api/response.rb +4 -3
- data/lib/playwright_api/route.rb +15 -4
- data/lib/playwright_api/selectors.rb +3 -7
- data/lib/playwright_api/touchscreen.rb +2 -1
- data/lib/playwright_api/video.rb +3 -1
- data/lib/playwright_api/web_socket.rb +4 -2
- data/lib/playwright_api/worker.rb +17 -5
- metadata +5 -2
@@ -1,28 +1,40 @@
|
|
1
1
|
module Playwright
|
2
|
-
# JSHandle represents an in-page JavaScript object. JSHandles can be created with the `
|
2
|
+
# JSHandle represents an in-page JavaScript object. JSHandles can be created with the [`method: Page.evaluateHandle`]
|
3
|
+
# method.
|
4
|
+
#
|
3
5
|
#
|
4
6
|
# ```js
|
5
7
|
# const windowHandle = await page.evaluateHandle(() => window);
|
6
8
|
# // ...
|
7
9
|
# ```
|
8
|
-
#
|
9
|
-
# JSHandle
|
10
|
+
#
|
11
|
+
# JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with
|
12
|
+
# [`method: JSHandle.dispose`]. JSHandles are auto-disposed when their origin frame gets navigated or the parent context
|
13
|
+
# gets destroyed.
|
14
|
+
#
|
15
|
+
# JSHandle instances can be used as an argument in [`method: Page.$eval`], [`method: Page.evaluate`] and
|
16
|
+
# [`method: Page.evaluateHandle`] methods.
|
10
17
|
class JSHandle < PlaywrightApi
|
11
18
|
|
12
|
-
# Returns either `null` or the object handle itself, if the object handle is an instance of ElementHandle
|
19
|
+
# Returns either `null` or the object handle itself, if the object handle is an instance of `ElementHandle`.
|
13
20
|
def as_element
|
14
21
|
raise NotImplementedError.new('as_element is not implemented yet.')
|
15
22
|
end
|
16
23
|
|
17
24
|
# The `jsHandle.dispose` method stops referencing the element handle.
|
18
25
|
def dispose
|
19
|
-
|
26
|
+
wrap_channel_owner(@channel_owner.dispose)
|
20
27
|
end
|
21
28
|
|
22
29
|
# Returns the return value of `pageFunction`
|
30
|
+
#
|
23
31
|
# This method passes this handle as the first argument to `pageFunction`.
|
24
|
-
#
|
32
|
+
#
|
33
|
+
# If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its
|
34
|
+
# value.
|
35
|
+
#
|
25
36
|
# Examples:
|
37
|
+
#
|
26
38
|
#
|
27
39
|
# ```js
|
28
40
|
# const tweetHandle = await page.$('.tweet .retweets');
|
@@ -33,15 +45,22 @@ module Playwright
|
|
33
45
|
end
|
34
46
|
|
35
47
|
# Returns the return value of `pageFunction` as in-page object (JSHandle).
|
48
|
+
#
|
36
49
|
# This method passes this handle as the first argument to `pageFunction`.
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
50
|
+
#
|
51
|
+
# The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns
|
52
|
+
# in-page object (JSHandle).
|
53
|
+
#
|
54
|
+
# If the function passed to the `jsHandle.evaluateHandle` returns a [Promise], then `jsHandle.evaluateHandle` would wait
|
55
|
+
# for the promise to resolve and return its value.
|
56
|
+
#
|
57
|
+
# See [`method: Page.evaluateHandle`] for more details.
|
40
58
|
def evaluate_handle(pageFunction, arg: nil)
|
41
59
|
raise NotImplementedError.new('evaluate_handle is not implemented yet.')
|
42
60
|
end
|
43
61
|
|
44
62
|
# The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
63
|
+
#
|
45
64
|
#
|
46
65
|
# ```js
|
47
66
|
# const handle = await page.evaluateHandle(() => ({window, document}));
|
@@ -61,7 +80,8 @@ module Playwright
|
|
61
80
|
|
62
81
|
# Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**.
|
63
82
|
#
|
64
|
-
# **NOTE** The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an
|
83
|
+
# > **NOTE** The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an
|
84
|
+
# error if the object has circular references.
|
65
85
|
def json_value
|
66
86
|
raise NotImplementedError.new('json_value is not implemented yet.')
|
67
87
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module Playwright
|
2
|
-
# Keyboard provides an api for managing a virtual keyboard. The high level api is `
|
3
|
-
#
|
2
|
+
# Keyboard provides an api for managing a virtual keyboard. The high level api is [`method: Keyboard.type`], which takes
|
3
|
+
# raw characters and generates proper keydown, keypress/input, and keyup events on your page.
|
4
|
+
#
|
5
|
+
# For finer control, you can use [`method: Keyboard.down`], [`method: Keyboard.up`], and [`method: Keyboard.insertText`]
|
6
|
+
# to manually fire events as if they were generated from a real keyboard.
|
7
|
+
#
|
4
8
|
# An example of holding down `Shift` in order to select and delete some text:
|
9
|
+
#
|
5
10
|
#
|
6
11
|
# ```js
|
7
12
|
# await page.keyboard.type('Hello World!');
|
@@ -15,14 +20,18 @@ module Playwright
|
|
15
20
|
# await page.keyboard.press('Backspace');
|
16
21
|
# // Result text will end up saying 'Hello!'
|
17
22
|
# ```
|
23
|
+
#
|
18
24
|
# An example of pressing uppercase `A`
|
25
|
+
#
|
19
26
|
#
|
20
27
|
# ```js
|
21
28
|
# await page.keyboard.press('Shift+KeyA');
|
22
29
|
# // or
|
23
30
|
# await page.keyboard.press('Shift+A');
|
24
31
|
# ```
|
32
|
+
#
|
25
33
|
# An example to trigger select-all with the keyboard
|
34
|
+
#
|
26
35
|
#
|
27
36
|
# ```js
|
28
37
|
# // on Windows and Linux
|
@@ -33,36 +42,62 @@ module Playwright
|
|
33
42
|
class Keyboard < PlaywrightApi
|
34
43
|
|
35
44
|
# Dispatches a `keydown` event.
|
36
|
-
#
|
37
|
-
# `
|
38
|
-
#
|
45
|
+
#
|
46
|
+
# `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
47
|
+
# value or a single character to generate the text for. A superset of the `key` values can be found
|
48
|
+
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
49
|
+
#
|
50
|
+
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
51
|
+
# `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
52
|
+
#
|
53
|
+
# Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
|
54
|
+
#
|
39
55
|
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
40
|
-
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective texts.
|
41
|
-
# If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier active. To release the modifier key, use `keyboard.up(key)`.
|
42
|
-
# After the key is pressed once, subsequent calls to `keyboard.down(key)` will have repeat set to true. To release the key, use `keyboard.up(key)`.
|
43
56
|
#
|
44
|
-
#
|
57
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
|
58
|
+
# texts.
|
59
|
+
#
|
60
|
+
# If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier
|
61
|
+
# active. To release the modifier key, use [`method: Keyboard.up`].
|
62
|
+
#
|
63
|
+
# After the key is pressed once, subsequent calls to [`method: Keyboard.down`] will have
|
64
|
+
# [repeat](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat) set to true. To release the key, use
|
65
|
+
# [`method: Keyboard.up`].
|
66
|
+
#
|
67
|
+
# > **NOTE** Modifier keys DO influence `keyboard.down`. Holding down `Shift` will type the text in upper case.
|
45
68
|
def down(key)
|
46
69
|
raise NotImplementedError.new('down is not implemented yet.')
|
47
70
|
end
|
48
71
|
|
49
72
|
# Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.
|
73
|
+
#
|
50
74
|
#
|
51
75
|
# ```js
|
52
76
|
# page.keyboard.insertText('嗨');
|
53
77
|
# ```
|
54
78
|
#
|
55
|
-
# **NOTE** Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
|
79
|
+
# > **NOTE** Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
|
56
80
|
def insert_text(text)
|
57
81
|
raise NotImplementedError.new('insert_text is not implemented yet.')
|
58
82
|
end
|
59
83
|
|
60
|
-
# `key` can specify the intended keyboardEvent.key
|
61
|
-
#
|
62
|
-
#
|
84
|
+
# `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
85
|
+
# value or a single character to generate the text for. A superset of the `key` values can be found
|
86
|
+
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
87
|
+
#
|
88
|
+
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
89
|
+
# `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
90
|
+
#
|
91
|
+
# Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
|
92
|
+
#
|
63
93
|
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
64
|
-
#
|
65
|
-
#
|
94
|
+
#
|
95
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
|
96
|
+
# texts.
|
97
|
+
#
|
98
|
+
# Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
|
99
|
+
# modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
100
|
+
#
|
66
101
|
#
|
67
102
|
# ```js
|
68
103
|
# const page = await browser.newPage();
|
@@ -75,20 +110,23 @@ module Playwright
|
|
75
110
|
# await page.screenshot({ path: 'O.png' });
|
76
111
|
# await browser.close();
|
77
112
|
# ```
|
78
|
-
#
|
113
|
+
#
|
114
|
+
# Shortcut for [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
79
115
|
def press(key, delay: nil)
|
80
116
|
raise NotImplementedError.new('press is not implemented yet.')
|
81
117
|
end
|
82
118
|
|
83
119
|
# Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
84
|
-
#
|
120
|
+
#
|
121
|
+
# To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
|
122
|
+
#
|
85
123
|
#
|
86
124
|
# ```js
|
87
125
|
# await page.keyboard.type('Hello'); // Types instantly
|
88
126
|
# await page.keyboard.type('World', {delay: 100}); // Types slower, like a user
|
89
127
|
# ```
|
90
128
|
#
|
91
|
-
# **NOTE** Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
|
129
|
+
# > **NOTE** Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
|
92
130
|
def type_text(text, delay: nil)
|
93
131
|
raise NotImplementedError.new('type_text is not implemented yet.')
|
94
132
|
end
|
data/lib/playwright_api/mouse.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Playwright
|
2
2
|
# The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
|
3
|
-
#
|
3
|
+
#
|
4
|
+
# Every `page` object has its own Mouse, accessible with [`property: Page.mouse`].
|
5
|
+
#
|
4
6
|
#
|
5
7
|
# ```js
|
6
8
|
# // Using ‘page.mouse’ to trace a 100x100 square.
|
@@ -14,7 +16,7 @@ module Playwright
|
|
14
16
|
# ```
|
15
17
|
class Mouse < PlaywrightApi
|
16
18
|
|
17
|
-
# Shortcut for `
|
19
|
+
# Shortcut for [`method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`].
|
18
20
|
def click(
|
19
21
|
x,
|
20
22
|
y,
|
@@ -24,7 +26,8 @@ module Playwright
|
|
24
26
|
raise NotImplementedError.new('click is not implemented yet.')
|
25
27
|
end
|
26
28
|
|
27
|
-
# Shortcut for `
|
29
|
+
# Shortcut for [`method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`], [`method: Mouse.down`] and
|
30
|
+
# [`method: Mouse.up`].
|
28
31
|
def dblclick(x, y, button: nil, delay: nil)
|
29
32
|
raise NotImplementedError.new('dblclick is not implemented yet.')
|
30
33
|
end
|
data/lib/playwright_api/page.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Playwright
|
2
|
-
#
|
2
|
+
# - extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
3
|
+
#
|
4
|
+
# Page provides methods to interact with a single tab in a `Browser`, or an
|
5
|
+
# [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser]
|
6
|
+
# instance might have multiple [Page] instances.
|
7
|
+
#
|
3
8
|
# This example creates a page, navigates it to a URL, and then saves a screenshot:
|
9
|
+
#
|
4
10
|
#
|
5
11
|
# ```js
|
6
12
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -14,13 +20,20 @@ module Playwright
|
|
14
20
|
# await browser.close();
|
15
21
|
# })();
|
16
22
|
# ```
|
17
|
-
#
|
23
|
+
#
|
24
|
+
# The Page class emits various events (described below) which can be handled using any of Node's native
|
25
|
+
# [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or
|
26
|
+
# `removeListener`.
|
27
|
+
#
|
18
28
|
# This example logs a message for a single page `load` event:
|
29
|
+
#
|
19
30
|
#
|
20
31
|
# ```js
|
21
32
|
# page.once('load', () => console.log('Page loaded!'));
|
22
33
|
# ```
|
34
|
+
#
|
23
35
|
# To unsubscribe from events use the `removeListener` method:
|
36
|
+
#
|
24
37
|
#
|
25
38
|
# ```js
|
26
39
|
# function logRequest(interceptedRequest) {
|
@@ -36,7 +49,8 @@ module Playwright
|
|
36
49
|
wrap_channel_owner(@channel_owner.accessibility)
|
37
50
|
end
|
38
51
|
|
39
|
-
# Browser-specific Coverage implementation, only available for Chromium atm. See
|
52
|
+
# Browser-specific Coverage implementation, only available for Chromium atm. See
|
53
|
+
# `ChromiumCoverage`(#class-chromiumcoverage) for more details.
|
40
54
|
def coverage # property
|
41
55
|
raise NotImplementedError.new('coverage is not implemented yet.')
|
42
56
|
end
|
@@ -53,50 +67,68 @@ module Playwright
|
|
53
67
|
wrap_channel_owner(@channel_owner.touchscreen)
|
54
68
|
end
|
55
69
|
|
56
|
-
# The method finds an element matching the specified selector within the page. If no elements match the selector, the
|
57
|
-
#
|
58
|
-
|
59
|
-
|
70
|
+
# The method finds an element matching the specified selector within the page. If no elements match the selector, the
|
71
|
+
# return value resolves to `null`.
|
72
|
+
#
|
73
|
+
# Shortcut for main frame's [`method: Frame.$`].
|
74
|
+
def query_selector(selector)
|
75
|
+
raise NotImplementedError.new('query_selector is not implemented yet.')
|
60
76
|
end
|
61
77
|
|
62
|
-
# The method finds all elements matching the specified selector within the page. If no elements match the selector, the
|
63
|
-
#
|
64
|
-
|
65
|
-
|
78
|
+
# The method finds all elements matching the specified selector within the page. If no elements match the selector, the
|
79
|
+
# return value resolves to `[]`.
|
80
|
+
#
|
81
|
+
# Shortcut for main frame's [`method: Frame.$$`].
|
82
|
+
def query_selector_all(selector)
|
83
|
+
raise NotImplementedError.new('query_selector_all is not implemented yet.')
|
66
84
|
end
|
67
85
|
|
68
|
-
# The method finds an element matching the specified selector within the page and passes it as a first argument to
|
69
|
-
#
|
86
|
+
# The method finds an element matching the specified selector within the page and passes it as a first argument to
|
87
|
+
# `pageFunction`. If no elements match the selector, the method throws an error. Returns the value of `pageFunction`.
|
88
|
+
#
|
89
|
+
# If `pageFunction` returns a [Promise], then [`method: Page.$eval`] would wait for the promise to resolve and return its
|
90
|
+
# value.
|
91
|
+
#
|
70
92
|
# Examples:
|
93
|
+
#
|
71
94
|
#
|
72
95
|
# ```js
|
73
96
|
# const searchValue = await page.$eval('#search', el => el.value);
|
74
97
|
# const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
|
75
98
|
# const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
|
76
99
|
# ```
|
77
|
-
#
|
78
|
-
|
79
|
-
|
100
|
+
#
|
101
|
+
# Shortcut for main frame's [`method: Frame.$eval`].
|
102
|
+
def eval_on_selector(selector, pageFunction, arg: nil)
|
103
|
+
raise NotImplementedError.new('eval_on_selector is not implemented yet.')
|
80
104
|
end
|
81
105
|
|
82
|
-
# The method finds all elements matching the specified selector within the page and passes an array of matched elements as
|
83
|
-
#
|
106
|
+
# The method finds all elements matching the specified selector within the page and passes an array of matched elements as
|
107
|
+
# a first argument to `pageFunction`. Returns the result of `pageFunction` invocation.
|
108
|
+
#
|
109
|
+
# If `pageFunction` returns a [Promise], then [`method: Page.$$eval`] would wait for the promise to resolve and return its
|
110
|
+
# value.
|
111
|
+
#
|
84
112
|
# Examples:
|
113
|
+
#
|
85
114
|
#
|
86
115
|
# ```js
|
87
116
|
# const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
|
88
117
|
# ```
|
89
|
-
def
|
90
|
-
raise NotImplementedError.new('
|
118
|
+
def eval_on_selector_all(selector, pageFunction, arg: nil)
|
119
|
+
raise NotImplementedError.new('eval_on_selector_all is not implemented yet.')
|
91
120
|
end
|
92
121
|
|
93
122
|
# Adds a script which would be evaluated in one of the following scenarios:
|
123
|
+
# - Whenever the page is navigated.
|
124
|
+
# - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly
|
125
|
+
# attached frame.
|
94
126
|
#
|
95
|
-
#
|
96
|
-
#
|
127
|
+
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
128
|
+
# the JavaScript environment, e.g. to seed `Math.random`.
|
97
129
|
#
|
98
|
-
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`.
|
99
130
|
# An example of overriding `Math.random` before the page loads:
|
131
|
+
#
|
100
132
|
#
|
101
133
|
# ```js
|
102
134
|
# // preload.js
|
@@ -107,20 +139,25 @@ module Playwright
|
|
107
139
|
# await page.addInitScript(preloadFile);
|
108
140
|
# ```
|
109
141
|
#
|
110
|
-
# **NOTE** The order of evaluation of multiple scripts installed via
|
142
|
+
# > **NOTE** The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
143
|
+
# [`method: Page.addInitScript`] is not defined.
|
111
144
|
def add_init_script(script, arg: nil)
|
112
145
|
raise NotImplementedError.new('add_init_script is not implemented yet.')
|
113
146
|
end
|
114
147
|
|
115
|
-
# Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
|
116
|
-
#
|
117
|
-
|
148
|
+
# Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
|
149
|
+
# fires or when the script content was injected into frame.
|
150
|
+
#
|
151
|
+
# Shortcut for main frame's [`method: Frame.addScriptTag`].
|
152
|
+
def add_script_tag(content: nil, path: nil, type: nil, url: nil)
|
118
153
|
raise NotImplementedError.new('add_script_tag is not implemented yet.')
|
119
154
|
end
|
120
155
|
|
121
|
-
# Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
|
122
|
-
#
|
123
|
-
|
156
|
+
# Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
|
157
|
+
# content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
|
158
|
+
#
|
159
|
+
# Shortcut for main frame's [`method: Frame.addStyleTag`].
|
160
|
+
def add_style_tag(content: nil, path: nil, url: nil)
|
124
161
|
raise NotImplementedError.new('add_style_tag is not implemented yet.')
|
125
162
|
end
|
126
163
|
|
@@ -130,49 +167,56 @@ module Playwright
|
|
130
167
|
end
|
131
168
|
|
132
169
|
# This method checks an element matching `selector` by performing the following steps:
|
170
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
171
|
+
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
|
172
|
+
# checked, this method returns immediately.
|
173
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
174
|
+
# element is detached during the checks, the whole action is retried.
|
175
|
+
# 1. Scroll the element into view if needed.
|
176
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
177
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
178
|
+
# 1. Ensure that the element is now checked. If not, this method rejects.
|
133
179
|
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
# Wait for actionability checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
137
|
-
# Scroll the element into view if needed.
|
138
|
-
# Use page.mouse to click in the center of the element.
|
139
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
140
|
-
# Ensure that the element is now checked. If not, this method rejects.
|
180
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
181
|
+
# Passing zero timeout disables this.
|
141
182
|
#
|
142
|
-
#
|
143
|
-
# Shortcut for main frame's `frame.check(selector[, options])`.
|
183
|
+
# Shortcut for main frame's [`method: Frame.check`].
|
144
184
|
def check(selector, force: nil, noWaitAfter: nil, timeout: nil)
|
145
185
|
raise NotImplementedError.new('check is not implemented yet.')
|
146
186
|
end
|
147
187
|
|
148
188
|
# This method clicks an element matching `selector` by performing the following steps:
|
189
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
190
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
191
|
+
# element is detached during the checks, the whole action is retried.
|
192
|
+
# 1. Scroll the element into view if needed.
|
193
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
|
194
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
149
195
|
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
# Scroll the element into view if needed.
|
153
|
-
# Use page.mouse to click in the center of the element, or the specified `position`.
|
154
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
196
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
197
|
+
# Passing zero timeout disables this.
|
155
198
|
#
|
156
|
-
#
|
157
|
-
# Shortcut for main frame's `frame.click(selector[, options])`.
|
199
|
+
# Shortcut for main frame's [`method: Frame.click`].
|
158
200
|
def click(
|
159
201
|
selector,
|
160
202
|
button: nil,
|
161
203
|
clickCount: nil,
|
162
204
|
delay: nil,
|
163
|
-
position: nil,
|
164
|
-
modifiers: nil,
|
165
205
|
force: nil,
|
206
|
+
modifiers: nil,
|
166
207
|
noWaitAfter: nil,
|
208
|
+
position: nil,
|
167
209
|
timeout: nil)
|
168
210
|
raise NotImplementedError.new('click is not implemented yet.')
|
169
211
|
end
|
170
212
|
|
171
|
-
# If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
|
213
|
+
# If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
|
214
|
+
# `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
|
215
|
+
#
|
172
216
|
# By default, `page.close()` **does not** run `beforeunload` handlers.
|
173
217
|
#
|
174
|
-
# **NOTE** if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned
|
175
|
-
# and should be handled manually via
|
218
|
+
# > **NOTE** if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned
|
219
|
+
# > and should be handled manually via [`event: Page.dialog`] event.
|
176
220
|
def close(runBeforeUnload: nil)
|
177
221
|
raise NotImplementedError.new('close is not implemented yet.')
|
178
222
|
end
|
@@ -188,47 +232,55 @@ module Playwright
|
|
188
232
|
end
|
189
233
|
|
190
234
|
# This method double clicks an element matching `selector` by performing the following steps:
|
235
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
236
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
237
|
+
# element is detached during the checks, the whole action is retried.
|
238
|
+
# 1. Scroll the element into view if needed.
|
239
|
+
# 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
|
240
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
|
241
|
+
# first click of the `dblclick()` triggers a navigation event, this method will reject.
|
191
242
|
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
# Scroll the element into view if needed.
|
195
|
-
# Use page.mouse to double click in the center of the element, or the specified `position`.
|
196
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the first click of the `dblclick()` triggers a navigation event, this method will reject.
|
243
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
244
|
+
# Passing zero timeout disables this.
|
197
245
|
#
|
198
|
-
#
|
246
|
+
# > **NOTE** `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
199
247
|
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# Shortcut for main frame's `frame.dblclick(selector[, options])`.
|
248
|
+
# Shortcut for main frame's [`method: Frame.dblclick`].
|
203
249
|
def dblclick(
|
204
250
|
selector,
|
205
251
|
button: nil,
|
206
252
|
delay: nil,
|
207
|
-
position: nil,
|
208
|
-
modifiers: nil,
|
209
253
|
force: nil,
|
254
|
+
modifiers: nil,
|
210
255
|
noWaitAfter: nil,
|
256
|
+
position: nil,
|
211
257
|
timeout: nil)
|
212
258
|
raise NotImplementedError.new('dblclick is not implemented yet.')
|
213
259
|
end
|
214
260
|
|
215
|
-
# The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
|
261
|
+
# The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
|
262
|
+
# is dispatched. This is equivalend to calling
|
263
|
+
# [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
264
|
+
#
|
216
265
|
#
|
217
266
|
# ```js
|
218
267
|
# await page.dispatchEvent('button#submit', 'click');
|
219
268
|
# ```
|
220
|
-
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
|
221
|
-
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
|
222
269
|
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
270
|
+
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
271
|
+
# and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
|
272
|
+
#
|
273
|
+
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
|
274
|
+
# - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
|
275
|
+
# - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
|
276
|
+
# - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
|
277
|
+
# - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
|
278
|
+
# - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
|
279
|
+
# - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
|
280
|
+
# - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
|
230
281
|
#
|
231
282
|
# You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
|
283
|
+
#
|
232
284
|
#
|
233
285
|
# ```js
|
234
286
|
# // Note you can only create DataTransfer in Chromium and Firefox
|
@@ -239,6 +291,7 @@ module Playwright
|
|
239
291
|
raise NotImplementedError.new('dispatch_event is not implemented yet.')
|
240
292
|
end
|
241
293
|
|
294
|
+
#
|
242
295
|
#
|
243
296
|
# ```js
|
244
297
|
# await page.evaluate(() => matchMedia('screen').matches);
|
@@ -258,6 +311,7 @@ module Playwright
|
|
258
311
|
# await page.evaluate(() => matchMedia('print').matches);
|
259
312
|
# // → false
|
260
313
|
# ```
|
314
|
+
#
|
261
315
|
#
|
262
316
|
# ```js
|
263
317
|
# await page.emulateMedia({ colorScheme: 'dark' });
|
@@ -272,10 +326,17 @@ module Playwright
|
|
272
326
|
raise NotImplementedError.new('emulate_media is not implemented yet.')
|
273
327
|
end
|
274
328
|
|
275
|
-
# Returns the value of the `pageFunction`
|
276
|
-
#
|
277
|
-
# If the function passed to the `page.evaluate` returns a
|
329
|
+
# Returns the value of the `pageFunction` invocation.
|
330
|
+
#
|
331
|
+
# If the function passed to the `page.evaluate` returns a [Promise], then `page.evaluate` would wait for the promise to
|
332
|
+
# resolve and return its value.
|
333
|
+
#
|
334
|
+
# If the function passed to the `page.evaluate` returns a non-[Serializable] value, then `page.evaluate` resolves to
|
335
|
+
# `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`:
|
336
|
+
# `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
|
337
|
+
#
|
278
338
|
# Passing argument to `pageFunction`:
|
339
|
+
#
|
279
340
|
#
|
280
341
|
# ```js
|
281
342
|
# const result = await page.evaluate(([x, y]) => {
|
@@ -283,34 +344,47 @@ module Playwright
|
|
283
344
|
# }, [7, 8]);
|
284
345
|
# console.log(result); // prints "56"
|
285
346
|
# ```
|
347
|
+
#
|
286
348
|
# A string can also be passed in instead of a function:
|
349
|
+
#
|
287
350
|
#
|
288
351
|
# ```js
|
289
352
|
# console.log(await page.evaluate('1 + 2')); // prints "3"
|
290
353
|
# const x = 10;
|
291
354
|
# console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
|
292
355
|
# ```
|
293
|
-
#
|
356
|
+
#
|
357
|
+
# `ElementHandle` instances can be passed as an argument to the `page.evaluate`:
|
358
|
+
#
|
294
359
|
#
|
295
360
|
# ```js
|
296
361
|
# const bodyHandle = await page.$('body');
|
297
362
|
# const html = await page.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
|
298
363
|
# await bodyHandle.dispose();
|
299
364
|
# ```
|
300
|
-
#
|
365
|
+
#
|
366
|
+
# Shortcut for main frame's [`method: Frame.evaluate`].
|
301
367
|
def evaluate(pageFunction, arg: nil)
|
302
368
|
raise NotImplementedError.new('evaluate is not implemented yet.')
|
303
369
|
end
|
304
370
|
|
305
|
-
# Returns the value of the `pageFunction`
|
306
|
-
#
|
307
|
-
#
|
371
|
+
# Returns the value of the `pageFunction` invocation as in-page object (JSHandle).
|
372
|
+
#
|
373
|
+
# The only difference between `page.evaluate` and `page.evaluateHandle` is that `page.evaluateHandle` returns in-page
|
374
|
+
# object (JSHandle).
|
375
|
+
#
|
376
|
+
# If the function passed to the `page.evaluateHandle` returns a [Promise], then `page.evaluateHandle` would wait for the
|
377
|
+
# promise to resolve and return its value.
|
378
|
+
#
|
308
379
|
# A string can also be passed in instead of a function:
|
380
|
+
#
|
309
381
|
#
|
310
382
|
# ```js
|
311
383
|
# const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
|
312
384
|
# ```
|
313
|
-
#
|
385
|
+
#
|
386
|
+
# `JSHandle` instances can be passed as an argument to the `page.evaluateHandle`:
|
387
|
+
#
|
314
388
|
#
|
315
389
|
# ```js
|
316
390
|
# const aHandle = await page.evaluateHandle(() => document.body);
|
@@ -322,13 +396,19 @@ module Playwright
|
|
322
396
|
raise NotImplementedError.new('evaluate_handle is not implemented yet.')
|
323
397
|
end
|
324
398
|
|
325
|
-
# The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
|
326
|
-
#
|
327
|
-
#
|
399
|
+
# The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
|
400
|
+
# executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
|
401
|
+
# a [Promise], it will be awaited.
|
402
|
+
#
|
403
|
+
# The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
|
404
|
+
# page: Page, frame: Frame }`.
|
405
|
+
#
|
406
|
+
# See [`method: BrowserContext.exposeBinding`] for the context-wide version.
|
328
407
|
#
|
329
|
-
# **NOTE** Functions installed via `page.exposeBinding` survive navigations.
|
408
|
+
# > **NOTE** Functions installed via `page.exposeBinding` survive navigations.
|
330
409
|
#
|
331
410
|
# An example of exposing page URL to all frames in a page:
|
411
|
+
#
|
332
412
|
#
|
333
413
|
# ```js
|
334
414
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -350,7 +430,9 @@ module Playwright
|
|
350
430
|
# await page.click('button');
|
351
431
|
# })();
|
352
432
|
# ```
|
433
|
+
#
|
353
434
|
# An example of passing an element handle:
|
435
|
+
#
|
354
436
|
#
|
355
437
|
# ```js
|
356
438
|
# await page.exposeBinding('clicked', async (source, element) => {
|
@@ -364,17 +446,21 @@ module Playwright
|
|
364
446
|
# <div>Or click me</div>
|
365
447
|
# `);
|
366
448
|
# ```
|
367
|
-
def expose_binding(name,
|
449
|
+
def expose_binding(name, callback, handle: nil)
|
368
450
|
raise NotImplementedError.new('expose_binding is not implemented yet.')
|
369
451
|
end
|
370
452
|
|
371
|
-
# The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
|
372
|
-
#
|
373
|
-
# See `browserContext.exposeFunction(name, playwrightFunction)` for context-wide exposed function.
|
453
|
+
# The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
|
454
|
+
# executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
|
374
455
|
#
|
375
|
-
#
|
456
|
+
# If the `callback` returns a [Promise], it will be awaited.
|
457
|
+
#
|
458
|
+
# See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.
|
459
|
+
#
|
460
|
+
# > **NOTE** Functions installed via `page.exposeFunction` survive navigations.
|
376
461
|
#
|
377
462
|
# An example of adding an `md5` function to the page:
|
463
|
+
#
|
378
464
|
#
|
379
465
|
# ```js
|
380
466
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -396,7 +482,9 @@ module Playwright
|
|
396
482
|
# await page.click('button');
|
397
483
|
# })();
|
398
484
|
# ```
|
485
|
+
#
|
399
486
|
# An example of adding a `window.readfile` function to the page:
|
487
|
+
#
|
400
488
|
#
|
401
489
|
# ```js
|
402
490
|
# const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
|
@@ -424,28 +512,37 @@ module Playwright
|
|
424
512
|
# await browser.close();
|
425
513
|
# })();
|
426
514
|
# ```
|
427
|
-
def expose_function(name,
|
515
|
+
def expose_function(name, callback)
|
428
516
|
raise NotImplementedError.new('expose_function is not implemented yet.')
|
429
517
|
end
|
430
518
|
|
431
|
-
# This method waits for an element matching `selector`, waits for actionability checks, focuses the
|
432
|
-
#
|
433
|
-
#
|
519
|
+
# This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, focuses the
|
520
|
+
# element, fills it and triggers an `input` event after filling. If the element matching `selector` is not an `<input>`,
|
521
|
+
# `<textarea>` or `[contenteditable]` element, this method throws an error. Note that you can pass an empty string to
|
522
|
+
# clear the input field.
|
523
|
+
#
|
524
|
+
# To send fine-grained keyboard events, use [`method: Page.type`].
|
525
|
+
#
|
526
|
+
# Shortcut for main frame's [`method: Frame.fill`]
|
434
527
|
def fill(selector, value, noWaitAfter: nil, timeout: nil)
|
435
528
|
raise NotImplementedError.new('fill is not implemented yet.')
|
436
529
|
end
|
437
530
|
|
438
|
-
# This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
|
439
|
-
#
|
531
|
+
# This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
|
532
|
+
# waits until a matching element appears in the DOM.
|
533
|
+
#
|
534
|
+
# Shortcut for main frame's [`method: Frame.focus`].
|
440
535
|
def focus(selector, timeout: nil)
|
441
536
|
raise NotImplementedError.new('focus is not implemented yet.')
|
442
537
|
end
|
443
538
|
|
444
539
|
# Returns frame matching the specified criteria. Either `name` or `url` must be specified.
|
540
|
+
#
|
445
541
|
#
|
446
542
|
# ```js
|
447
543
|
# const frame = page.frame('frame-name');
|
448
544
|
# ```
|
545
|
+
#
|
449
546
|
#
|
450
547
|
# ```js
|
451
548
|
# const frame = page.frame({ url: /.*domain.*/ });
|
@@ -464,52 +561,63 @@ module Playwright
|
|
464
561
|
raise NotImplementedError.new('get_attribute is not implemented yet.')
|
465
562
|
end
|
466
563
|
|
467
|
-
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
564
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
565
|
+
# last redirect. If can not go back, returns `null`.
|
566
|
+
#
|
468
567
|
# Navigate to the previous page in history.
|
469
568
|
def go_back(timeout: nil, waitUntil: nil)
|
470
569
|
raise NotImplementedError.new('go_back is not implemented yet.')
|
471
570
|
end
|
472
571
|
|
473
|
-
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
572
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
573
|
+
# last redirect. If can not go forward, returns `null`.
|
574
|
+
#
|
474
575
|
# Navigate to the next page in history.
|
475
576
|
def go_forward(timeout: nil, waitUntil: nil)
|
476
577
|
raise NotImplementedError.new('go_forward is not implemented yet.')
|
477
578
|
end
|
478
579
|
|
479
|
-
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
480
|
-
#
|
580
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
581
|
+
# last redirect.
|
481
582
|
#
|
482
|
-
#
|
483
|
-
#
|
484
|
-
#
|
485
|
-
# the
|
486
|
-
# the
|
583
|
+
# `page.goto` will throw an error if:
|
584
|
+
# - there's an SSL error (e.g. in case of self-signed certificates).
|
585
|
+
# - target URL is invalid.
|
586
|
+
# - the `timeout` is exceeded during navigation.
|
587
|
+
# - the remote server does not respond or is unreachable.
|
588
|
+
# - the main resource failed to load.
|
487
589
|
#
|
488
|
-
# `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
|
590
|
+
# `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
|
591
|
+
# Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
|
592
|
+
# [`method: Response.status`].
|
489
593
|
#
|
490
|
-
# **NOTE** `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
|
491
|
-
#
|
594
|
+
# > **NOTE** `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
|
595
|
+
# `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
|
596
|
+
# > **NOTE** Headless mode doesn't support navigation to a PDF document. See the
|
597
|
+
# [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
492
598
|
#
|
493
|
-
# Shortcut for main frame's `
|
494
|
-
def goto(url,
|
495
|
-
wrap_channel_owner(@channel_owner.goto(url, timeout: timeout, waitUntil: waitUntil
|
599
|
+
# Shortcut for main frame's [`method: Frame.goto`]
|
600
|
+
def goto(url, referer: nil, timeout: nil, waitUntil: nil)
|
601
|
+
wrap_channel_owner(@channel_owner.goto(url, referer: referer, timeout: timeout, waitUntil: waitUntil))
|
496
602
|
end
|
497
603
|
|
498
604
|
# This method hovers over an element matching `selector` by performing the following steps:
|
605
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
606
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
607
|
+
# element is detached during the checks, the whole action is retried.
|
608
|
+
# 1. Scroll the element into view if needed.
|
609
|
+
# 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
|
610
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
499
611
|
#
|
500
|
-
#
|
501
|
-
#
|
502
|
-
# Scroll the element into view if needed.
|
503
|
-
# Use page.mouse to hover over the center of the element, or the specified `position`.
|
504
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
612
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
613
|
+
# Passing zero timeout disables this.
|
505
614
|
#
|
506
|
-
#
|
507
|
-
# Shortcut for main frame's `frame.hover(selector[, options])`.
|
615
|
+
# Shortcut for main frame's [`method: Frame.hover`].
|
508
616
|
def hover(
|
509
617
|
selector,
|
510
|
-
position: nil,
|
511
|
-
modifiers: nil,
|
512
618
|
force: nil,
|
619
|
+
modifiers: nil,
|
620
|
+
position: nil,
|
513
621
|
timeout: nil)
|
514
622
|
raise NotImplementedError.new('hover is not implemented yet.')
|
515
623
|
end
|
@@ -524,11 +632,41 @@ module Playwright
|
|
524
632
|
raise NotImplementedError.new('inner_text is not implemented yet.')
|
525
633
|
end
|
526
634
|
|
635
|
+
# Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
636
|
+
def checked?(selector, timeout: nil)
|
637
|
+
raise NotImplementedError.new('checked? is not implemented yet.')
|
638
|
+
end
|
639
|
+
|
527
640
|
# Indicates that the page has been closed.
|
528
641
|
def closed?
|
529
642
|
raise NotImplementedError.new('closed? is not implemented yet.')
|
530
643
|
end
|
531
644
|
|
645
|
+
# Returns whether the element is disabled, the opposite of [enabled](./actionability.md#enabled).
|
646
|
+
def disabled?(selector, timeout: nil)
|
647
|
+
raise NotImplementedError.new('disabled? is not implemented yet.')
|
648
|
+
end
|
649
|
+
|
650
|
+
# Returns whether the element is [editable](./actionability.md#editable).
|
651
|
+
def editable?(selector, timeout: nil)
|
652
|
+
raise NotImplementedError.new('editable? is not implemented yet.')
|
653
|
+
end
|
654
|
+
|
655
|
+
# Returns whether the element is [enabled](./actionability.md#enabled).
|
656
|
+
def enabled?(selector, timeout: nil)
|
657
|
+
raise NotImplementedError.new('enabled? is not implemented yet.')
|
658
|
+
end
|
659
|
+
|
660
|
+
# Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
|
661
|
+
def hidden?(selector, timeout: nil)
|
662
|
+
raise NotImplementedError.new('hidden? is not implemented yet.')
|
663
|
+
end
|
664
|
+
|
665
|
+
# Returns whether the element is [visible](./actionability.md#visible).
|
666
|
+
def visible?(selector, timeout: nil)
|
667
|
+
raise NotImplementedError.new('visible? is not implemented yet.')
|
668
|
+
end
|
669
|
+
|
532
670
|
# The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
|
533
671
|
def main_frame
|
534
672
|
wrap_channel_owner(@channel_owner.main_frame)
|
@@ -541,11 +679,14 @@ module Playwright
|
|
541
679
|
|
542
680
|
# Returns the PDF buffer.
|
543
681
|
#
|
544
|
-
# **NOTE** Generating a pdf is currently only supported in Chromium headless.
|
682
|
+
# > **NOTE** Generating a pdf is currently only supported in Chromium headless.
|
545
683
|
#
|
546
|
-
# `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
|
684
|
+
# `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
|
685
|
+
# [`method: Page.emulateMedia`] before calling `page.pdf()`:
|
547
686
|
#
|
548
|
-
# **NOTE** By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
|
687
|
+
# > **NOTE** By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
|
688
|
+
# [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
|
689
|
+
# force rendering of exact colors.
|
549
690
|
#
|
550
691
|
#
|
551
692
|
# ```js
|
@@ -553,63 +694,72 @@ module Playwright
|
|
553
694
|
# await page.emulateMedia({media: 'screen'});
|
554
695
|
# await page.pdf({path: 'page.pdf'});
|
555
696
|
# ```
|
697
|
+
#
|
556
698
|
# The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels.
|
557
|
-
# A few examples:
|
558
699
|
#
|
559
|
-
#
|
560
|
-
# `page.pdf({width:
|
561
|
-
# `page.pdf({width: '
|
700
|
+
# A few examples:
|
701
|
+
# - `page.pdf({width: 100})` - prints with width set to 100 pixels
|
702
|
+
# - `page.pdf({width: '100px'})` - prints with width set to 100 pixels
|
703
|
+
# - `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
|
562
704
|
#
|
563
705
|
# All possible units are:
|
564
|
-
#
|
565
|
-
# `
|
566
|
-
# `
|
567
|
-
# `
|
568
|
-
# `mm` - millimeter
|
706
|
+
# - `px` - pixel
|
707
|
+
# - `in` - inch
|
708
|
+
# - `cm` - centimeter
|
709
|
+
# - `mm` - millimeter
|
569
710
|
#
|
570
711
|
# The `format` options are:
|
712
|
+
# - `Letter`: 8.5in x 11in
|
713
|
+
# - `Legal`: 8.5in x 14in
|
714
|
+
# - `Tabloid`: 11in x 17in
|
715
|
+
# - `Ledger`: 17in x 11in
|
716
|
+
# - `A0`: 33.1in x 46.8in
|
717
|
+
# - `A1`: 23.4in x 33.1in
|
718
|
+
# - `A2`: 16.54in x 23.4in
|
719
|
+
# - `A3`: 11.7in x 16.54in
|
720
|
+
# - `A4`: 8.27in x 11.7in
|
721
|
+
# - `A5`: 5.83in x 8.27in
|
722
|
+
# - `A6`: 4.13in x 5.83in
|
571
723
|
#
|
572
|
-
# `
|
573
|
-
#
|
574
|
-
#
|
575
|
-
# `Ledger`: 17in x 11in
|
576
|
-
# `A0`: 33.1in x 46.8in
|
577
|
-
# `A1`: 23.4in x 33.1in
|
578
|
-
# `A2`: 16.54in x 23.4in
|
579
|
-
# `A3`: 11.7in x 16.54in
|
580
|
-
# `A4`: 8.27in x 11.7in
|
581
|
-
# `A5`: 5.83in x 8.27in
|
582
|
-
# `A6`: 4.13in x 5.83in
|
583
|
-
#
|
584
|
-
#
|
585
|
-
# **NOTE** `headerTemplate` and `footerTemplate` markup have the following limitations:
|
586
|
-
#
|
587
|
-
# Script tags inside templates are not evaluated.
|
588
|
-
# Page styles are not visible inside templates.
|
724
|
+
# > **NOTE** `headerTemplate` and `footerTemplate` markup have the following limitations:
|
725
|
+
# > 1. Script tags inside templates are not evaluated.
|
726
|
+
# > 2. Page styles are not visible inside templates.
|
589
727
|
def pdf(
|
590
|
-
path: nil,
|
591
|
-
scale: nil,
|
592
728
|
displayHeaderFooter: nil,
|
593
|
-
headerTemplate: nil,
|
594
729
|
footerTemplate: nil,
|
595
|
-
printBackground: nil,
|
596
|
-
landscape: nil,
|
597
|
-
pageRanges: nil,
|
598
730
|
format: nil,
|
599
|
-
|
731
|
+
headerTemplate: nil,
|
600
732
|
height: nil,
|
733
|
+
landscape: nil,
|
601
734
|
margin: nil,
|
602
|
-
|
735
|
+
pageRanges: nil,
|
736
|
+
path: nil,
|
737
|
+
preferCSSPageSize: nil,
|
738
|
+
printBackground: nil,
|
739
|
+
scale: nil,
|
740
|
+
width: nil)
|
603
741
|
raise NotImplementedError.new('pdf is not implemented yet.')
|
604
742
|
end
|
605
743
|
|
606
|
-
# Focuses the element, and then uses `
|
607
|
-
#
|
608
|
-
# `
|
609
|
-
#
|
744
|
+
# Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
745
|
+
#
|
746
|
+
# `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
747
|
+
# value or a single character to generate the text for. A superset of the `key` values can be found
|
748
|
+
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
749
|
+
#
|
750
|
+
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
751
|
+
# `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
752
|
+
#
|
753
|
+
# Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
|
754
|
+
#
|
610
755
|
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
611
|
-
#
|
612
|
-
#
|
756
|
+
#
|
757
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
|
758
|
+
# texts.
|
759
|
+
#
|
760
|
+
# Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
|
761
|
+
# modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
762
|
+
#
|
613
763
|
#
|
614
764
|
# ```js
|
615
765
|
# const page = await browser.newPage();
|
@@ -631,17 +781,20 @@ module Playwright
|
|
631
781
|
raise NotImplementedError.new('press is not implemented yet.')
|
632
782
|
end
|
633
783
|
|
634
|
-
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
784
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
785
|
+
# last redirect.
|
635
786
|
def reload(timeout: nil, waitUntil: nil)
|
636
787
|
raise NotImplementedError.new('reload is not implemented yet.')
|
637
788
|
end
|
638
789
|
|
639
790
|
# Routing provides the capability to modify network requests that are made by a page.
|
791
|
+
#
|
640
792
|
# Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
641
793
|
#
|
642
|
-
# **NOTE** The handler will only be called for the first url if the response is a redirect.
|
794
|
+
# > **NOTE** The handler will only be called for the first url if the response is a redirect.
|
643
795
|
#
|
644
796
|
# An example of a naïve handler that aborts all image requests:
|
797
|
+
#
|
645
798
|
#
|
646
799
|
# ```js
|
647
800
|
# const page = await browser.newPage();
|
@@ -649,7 +802,9 @@ module Playwright
|
|
649
802
|
# await page.goto('https://example.com');
|
650
803
|
# await browser.close();
|
651
804
|
# ```
|
805
|
+
#
|
652
806
|
# or the same snippet using a regex pattern instead:
|
807
|
+
#
|
653
808
|
#
|
654
809
|
# ```js
|
655
810
|
# const page = await browser.newPage();
|
@@ -657,29 +812,35 @@ module Playwright
|
|
657
812
|
# await page.goto('https://example.com');
|
658
813
|
# await browser.close();
|
659
814
|
# ```
|
660
|
-
# Page routes take precedence over browser context routes (set up with `browserContext.route(url, handler)`) when request matches both handlers.
|
661
815
|
#
|
662
|
-
#
|
816
|
+
# Page routes take precedence over browser context routes (set up with [`method: BrowserContext.route`]) when request
|
817
|
+
# matches both handlers.
|
818
|
+
#
|
819
|
+
# > **NOTE** Enabling routing disables http cache.
|
663
820
|
def route(url, handler)
|
664
821
|
raise NotImplementedError.new('route is not implemented yet.')
|
665
822
|
end
|
666
823
|
|
667
824
|
# Returns the buffer with the captured screenshot.
|
668
825
|
#
|
669
|
-
# **NOTE** Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
|
826
|
+
# > **NOTE** Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
|
827
|
+
# discussion.
|
670
828
|
def screenshot(
|
671
|
-
path: nil,
|
672
|
-
type: nil,
|
673
|
-
quality: nil,
|
674
|
-
fullPage: nil,
|
675
829
|
clip: nil,
|
830
|
+
fullPage: nil,
|
676
831
|
omitBackground: nil,
|
677
|
-
|
678
|
-
|
832
|
+
path: nil,
|
833
|
+
quality: nil,
|
834
|
+
timeout: nil,
|
835
|
+
type: nil)
|
836
|
+
wrap_channel_owner(@channel_owner.screenshot(clip: clip, fullPage: fullPage, omitBackground: omitBackground, path: path, quality: quality, timeout: timeout, type: type))
|
679
837
|
end
|
680
838
|
|
681
839
|
# Returns the array of option values that have been successfully selected.
|
682
|
-
#
|
840
|
+
#
|
841
|
+
# Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element
|
842
|
+
# matching `selector`, the method throws an error.
|
843
|
+
#
|
683
844
|
#
|
684
845
|
# ```js
|
685
846
|
# // single selection matching the value
|
@@ -692,7 +853,8 @@ module Playwright
|
|
692
853
|
# page.selectOption('select#colors', ['red', 'green', 'blue']);
|
693
854
|
#
|
694
855
|
# ```
|
695
|
-
#
|
856
|
+
#
|
857
|
+
# Shortcut for main frame's [`method: Frame.selectOption`]
|
696
858
|
def select_option(selector, values, noWaitAfter: nil, timeout: nil)
|
697
859
|
raise NotImplementedError.new('select_option is not implemented yet.')
|
698
860
|
end
|
@@ -702,42 +864,51 @@ module Playwright
|
|
702
864
|
end
|
703
865
|
|
704
866
|
# This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
867
|
+
# - [`method: Page.goBack`]
|
868
|
+
# - [`method: Page.goForward`]
|
869
|
+
# - [`method: Page.goto`]
|
870
|
+
# - [`method: Page.reload`]
|
871
|
+
# - [`method: Page.setContent`]
|
872
|
+
# - [`method: Page.waitForNavigation`]
|
705
873
|
#
|
706
|
-
# `
|
707
|
-
# `
|
708
|
-
# `page.goto(url[, options])`
|
709
|
-
# `page.reload([options])`
|
710
|
-
# `page.setContent(html[, options])`
|
711
|
-
# `page.waitForNavigation([options])`
|
712
|
-
#
|
713
|
-
#
|
714
|
-
# **NOTE** `page.setDefaultNavigationTimeout(timeout)` takes priority over `page.setDefaultTimeout(timeout)`, `browserContext.setDefaultTimeout(timeout)` and `browserContext.setDefaultNavigationTimeout(timeout)`.
|
874
|
+
# > **NOTE** [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
|
875
|
+
# [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
|
715
876
|
def set_default_navigation_timeout(timeout)
|
716
877
|
raise NotImplementedError.new('set_default_navigation_timeout is not implemented yet.')
|
717
878
|
end
|
879
|
+
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
718
880
|
|
719
881
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
720
882
|
#
|
721
|
-
# **NOTE** `
|
883
|
+
# > **NOTE** [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`].
|
722
884
|
def set_default_timeout(timeout)
|
723
885
|
raise NotImplementedError.new('set_default_timeout is not implemented yet.')
|
724
886
|
end
|
887
|
+
alias_method :default_timeout=, :set_default_timeout
|
725
888
|
|
726
889
|
# The extra HTTP headers will be sent with every request the page initiates.
|
727
890
|
#
|
728
|
-
# **NOTE** page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.
|
891
|
+
# > **NOTE** page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.
|
729
892
|
def set_extra_http_headers(headers)
|
730
893
|
raise NotImplementedError.new('set_extra_http_headers is not implemented yet.')
|
731
894
|
end
|
895
|
+
alias_method :extra_http_headers=, :set_extra_http_headers
|
732
896
|
|
733
|
-
# This method expects `selector` to point to an
|
734
|
-
#
|
897
|
+
# This method expects `selector` to point to an
|
898
|
+
# [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
899
|
+
#
|
900
|
+
# Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
|
901
|
+
# are resolved relative to the the current working directory. For empty array, clears the selected files.
|
735
902
|
def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
|
736
903
|
raise NotImplementedError.new('set_input_files is not implemented yet.')
|
737
904
|
end
|
738
905
|
|
739
|
-
# In the case of multiple pages in a single browser, each page can have its own viewport size. However,
|
740
|
-
# `
|
906
|
+
# In the case of multiple pages in a single browser, each page can have its own viewport size. However,
|
907
|
+
# [`method: Browser.newContext`] allows to set viewport size (and more) for all pages in the context at once.
|
908
|
+
#
|
909
|
+
# `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
|
910
|
+
# viewport size before navigating to the page.
|
911
|
+
#
|
741
912
|
#
|
742
913
|
# ```js
|
743
914
|
# const page = await browser.newPage();
|
@@ -748,28 +919,30 @@ module Playwright
|
|
748
919
|
# await page.goto('https://example.com');
|
749
920
|
# ```
|
750
921
|
def set_viewport_size(viewportSize)
|
751
|
-
|
922
|
+
wrap_channel_owner(@channel_owner.set_viewport_size(viewportSize))
|
752
923
|
end
|
924
|
+
alias_method :viewport_size=, :set_viewport_size
|
753
925
|
|
754
926
|
# This method taps an element matching `selector` by performing the following steps:
|
927
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
928
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
929
|
+
# element is detached during the checks, the whole action is retried.
|
930
|
+
# 1. Scroll the element into view if needed.
|
931
|
+
# 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
|
932
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
755
933
|
#
|
756
|
-
#
|
757
|
-
#
|
758
|
-
# Scroll the element into view if needed.
|
759
|
-
# Use page.touchscreen to tap the center of the element, or the specified `position`.
|
760
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
761
|
-
#
|
762
|
-
# When all steps combined have not finished during the specified `timeout`, this method rejects with a TimeoutError. Passing zero timeout disables this.
|
934
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
935
|
+
# Passing zero timeout disables this.
|
763
936
|
#
|
764
|
-
# **NOTE** `page.tap()` requires that the `hasTouch` option of the browser context be set to true.
|
937
|
+
# > **NOTE** `page.tap()` requires that the `hasTouch` option of the browser context be set to true.
|
765
938
|
#
|
766
|
-
# Shortcut for main frame's `
|
939
|
+
# Shortcut for main frame's [`method: Frame.tap`].
|
767
940
|
def tap_point(
|
768
941
|
selector,
|
769
|
-
|
942
|
+
force: nil,
|
770
943
|
modifiers: nil,
|
771
944
|
noWaitAfter: nil,
|
772
|
-
|
945
|
+
position: nil,
|
773
946
|
timeout: nil)
|
774
947
|
raise NotImplementedError.new('tap_point is not implemented yet.')
|
775
948
|
end
|
@@ -779,19 +952,23 @@ module Playwright
|
|
779
952
|
raise NotImplementedError.new('text_content is not implemented yet.')
|
780
953
|
end
|
781
954
|
|
782
|
-
# Returns the page's title. Shortcut for main frame's `
|
955
|
+
# Returns the page's title. Shortcut for main frame's [`method: Frame.title`].
|
783
956
|
def title
|
784
957
|
raise NotImplementedError.new('title is not implemented yet.')
|
785
958
|
end
|
786
959
|
|
787
|
-
# Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
|
788
|
-
#
|
960
|
+
# Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
|
961
|
+
# fine-grained keyboard events. To fill values in form fields, use [`method: Page.fill`].
|
962
|
+
#
|
963
|
+
# To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
|
964
|
+
#
|
789
965
|
#
|
790
966
|
# ```js
|
791
967
|
# await page.type('#mytextarea', 'Hello'); // Types instantly
|
792
968
|
# await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
|
793
969
|
# ```
|
794
|
-
#
|
970
|
+
#
|
971
|
+
# Shortcut for main frame's [`method: Frame.type`].
|
795
972
|
def type_text(
|
796
973
|
selector,
|
797
974
|
text,
|
@@ -802,27 +979,30 @@ module Playwright
|
|
802
979
|
end
|
803
980
|
|
804
981
|
# This method unchecks an element matching `selector` by performing the following steps:
|
982
|
+
# 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
983
|
+
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
|
984
|
+
# unchecked, this method returns immediately.
|
985
|
+
# 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
|
986
|
+
# element is detached during the checks, the whole action is retried.
|
987
|
+
# 1. Scroll the element into view if needed.
|
988
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
989
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
990
|
+
# 1. Ensure that the element is now unchecked. If not, this method rejects.
|
805
991
|
#
|
806
|
-
#
|
807
|
-
#
|
808
|
-
# Wait for actionability checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
809
|
-
# Scroll the element into view if needed.
|
810
|
-
# Use page.mouse to click in the center of the element.
|
811
|
-
# Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
812
|
-
# Ensure that the element is now unchecked. If not, this method rejects.
|
992
|
+
# When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
|
993
|
+
# Passing zero timeout disables this.
|
813
994
|
#
|
814
|
-
#
|
815
|
-
# Shortcut for main frame's `frame.uncheck(selector[, options])`.
|
995
|
+
# Shortcut for main frame's [`method: Frame.uncheck`].
|
816
996
|
def uncheck(selector, force: nil, noWaitAfter: nil, timeout: nil)
|
817
997
|
raise NotImplementedError.new('uncheck is not implemented yet.')
|
818
998
|
end
|
819
999
|
|
820
|
-
# Removes a route created with `
|
1000
|
+
# Removes a route created with [`method: Page.route`]. When `handler` is not specified, removes all routes for the `url`.
|
821
1001
|
def unroute(url, handler: nil)
|
822
1002
|
raise NotImplementedError.new('unroute is not implemented yet.')
|
823
1003
|
end
|
824
1004
|
|
825
|
-
# Shortcut for main frame's `
|
1005
|
+
# Shortcut for main frame's [`method: Frame.url`].
|
826
1006
|
def url
|
827
1007
|
raise NotImplementedError.new('url is not implemented yet.')
|
828
1008
|
end
|
@@ -833,17 +1013,21 @@ module Playwright
|
|
833
1013
|
end
|
834
1014
|
|
835
1015
|
def viewport_size
|
836
|
-
|
1016
|
+
wrap_channel_owner(@channel_owner.viewport_size)
|
837
1017
|
end
|
838
1018
|
|
839
1019
|
# Returns the event data value.
|
840
|
-
#
|
1020
|
+
#
|
1021
|
+
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
1022
|
+
# value. Will throw an error if the page is closed before the event is fired.
|
841
1023
|
def wait_for_event(event, optionsOrPredicate: nil)
|
842
1024
|
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
843
1025
|
end
|
844
1026
|
|
845
1027
|
# Returns when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.
|
1028
|
+
#
|
846
1029
|
# The `waitForFunction` can be used to observe viewport size change:
|
1030
|
+
#
|
847
1031
|
#
|
848
1032
|
# ```js
|
849
1033
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -857,24 +1041,31 @@ module Playwright
|
|
857
1041
|
# await browser.close();
|
858
1042
|
# })();
|
859
1043
|
# ```
|
1044
|
+
#
|
860
1045
|
# To pass an argument to the predicate of `page.waitForFunction` function:
|
1046
|
+
#
|
861
1047
|
#
|
862
1048
|
# ```js
|
863
1049
|
# const selector = '.foo';
|
864
1050
|
# await page.waitForFunction(selector => !!document.querySelector(selector), selector);
|
865
1051
|
# ```
|
866
|
-
#
|
1052
|
+
#
|
1053
|
+
# Shortcut for main frame's [`method: Frame.waitForFunction`].
|
867
1054
|
def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
|
868
1055
|
raise NotImplementedError.new('wait_for_function is not implemented yet.')
|
869
1056
|
end
|
870
1057
|
|
871
1058
|
# Returns when the required load state has been reached.
|
872
|
-
#
|
1059
|
+
#
|
1060
|
+
# This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
|
1061
|
+
# when this method is called. If current document has already reached the required state, resolves immediately.
|
1062
|
+
#
|
873
1063
|
#
|
874
1064
|
# ```js
|
875
1065
|
# await page.click('button'); // Click triggers navigation.
|
876
1066
|
# await page.waitForLoadState(); // The promise resolves after 'load' event.
|
877
1067
|
# ```
|
1068
|
+
#
|
878
1069
|
#
|
879
1070
|
# ```js
|
880
1071
|
# const [popup] = await Promise.all([
|
@@ -884,13 +1075,20 @@ module Playwright
|
|
884
1075
|
# await popup.waitForLoadState('domcontentloaded'); // The promise resolves after 'domcontentloaded' event.
|
885
1076
|
# console.log(await popup.title()); // Popup is ready to use.
|
886
1077
|
# ```
|
887
|
-
#
|
1078
|
+
#
|
1079
|
+
# Shortcut for main frame's [`method: Frame.waitForLoadState`].
|
888
1080
|
def wait_for_load_state(state: nil, timeout: nil)
|
889
1081
|
raise NotImplementedError.new('wait_for_load_state is not implemented yet.')
|
890
1082
|
end
|
891
1083
|
|
892
|
-
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
893
|
-
#
|
1084
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
1085
|
+
# last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will
|
1086
|
+
# resolve with `null`.
|
1087
|
+
#
|
1088
|
+
# This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
|
1089
|
+
# cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
|
1090
|
+
# Consider this example:
|
1091
|
+
#
|
894
1092
|
#
|
895
1093
|
# ```js
|
896
1094
|
# const [response] = await Promise.all([
|
@@ -898,19 +1096,24 @@ module Playwright
|
|
898
1096
|
# page.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
|
899
1097
|
# ]);
|
900
1098
|
# ```
|
901
|
-
#
|
902
|
-
#
|
1099
|
+
#
|
1100
|
+
# **NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
|
1101
|
+
# considered a navigation.
|
1102
|
+
#
|
1103
|
+
# Shortcut for main frame's [`method: Frame.waitForNavigation`].
|
903
1104
|
def wait_for_navigation(timeout: nil, url: nil, waitUntil: nil)
|
904
1105
|
raise NotImplementedError.new('wait_for_navigation is not implemented yet.')
|
905
1106
|
end
|
906
1107
|
|
907
1108
|
# Waits for the matching request and returns it.
|
1109
|
+
#
|
908
1110
|
#
|
909
1111
|
# ```js
|
910
1112
|
# const firstRequest = await page.waitForRequest('http://example.com/resource');
|
911
1113
|
# const finalRequest = await page.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');
|
912
1114
|
# return firstRequest.url();
|
913
1115
|
# ```
|
1116
|
+
#
|
914
1117
|
#
|
915
1118
|
# ```js
|
916
1119
|
# await page.waitForRequest(request => request.url().searchParams.get('foo') === 'bar' && request.url().searchParams.get('foo2') === 'bar2');
|
@@ -920,6 +1123,7 @@ module Playwright
|
|
920
1123
|
end
|
921
1124
|
|
922
1125
|
# Returns the matched response.
|
1126
|
+
#
|
923
1127
|
#
|
924
1128
|
# ```js
|
925
1129
|
# const firstResponse = await page.waitForResponse('https://example.com/resource');
|
@@ -930,9 +1134,15 @@ module Playwright
|
|
930
1134
|
raise NotImplementedError.new('wait_for_response is not implemented yet.')
|
931
1135
|
end
|
932
1136
|
|
933
|
-
# Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
|
934
|
-
#
|
1137
|
+
# Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
|
1138
|
+
# `detached`.
|
1139
|
+
#
|
1140
|
+
# Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
|
1141
|
+
# the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
|
1142
|
+
# selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
|
1143
|
+
#
|
935
1144
|
# This method works across navigations:
|
1145
|
+
#
|
936
1146
|
#
|
937
1147
|
# ```js
|
938
1148
|
# const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
|
@@ -955,32 +1165,37 @@ module Playwright
|
|
955
1165
|
end
|
956
1166
|
|
957
1167
|
# Waits for the given `timeout` in milliseconds.
|
958
|
-
#
|
1168
|
+
#
|
1169
|
+
# Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
|
1170
|
+
# flaky. Use signals such as network events, selectors becoming visible and others instead.
|
1171
|
+
#
|
959
1172
|
#
|
960
1173
|
# ```js
|
961
1174
|
# // wait for 1 second
|
962
1175
|
# await page.waitForTimeout(1000);
|
963
1176
|
# ```
|
964
|
-
#
|
1177
|
+
#
|
1178
|
+
# Shortcut for main frame's [`method: Frame.waitForTimeout`].
|
965
1179
|
def wait_for_timeout(timeout)
|
966
1180
|
raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
|
967
1181
|
end
|
968
1182
|
|
969
|
-
# This method returns all of the dedicated WebWorkers
|
1183
|
+
# This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
|
1184
|
+
# associated with the page.
|
970
1185
|
#
|
971
|
-
# **NOTE** This does not contain ServiceWorkers
|
1186
|
+
# > **NOTE** This does not contain ServiceWorkers
|
972
1187
|
def workers
|
973
1188
|
raise NotImplementedError.new('workers is not implemented yet.')
|
974
1189
|
end
|
975
1190
|
|
976
1191
|
# @nodoc
|
977
|
-
def
|
978
|
-
wrap_channel_owner(@channel_owner.
|
1192
|
+
def after_initialize
|
1193
|
+
wrap_channel_owner(@channel_owner.after_initialize)
|
979
1194
|
end
|
980
1195
|
|
981
1196
|
# @nodoc
|
982
|
-
def
|
983
|
-
wrap_channel_owner(@channel_owner.
|
1197
|
+
def owned_context=(req)
|
1198
|
+
wrap_channel_owner(@channel_owner.owned_context=(req))
|
984
1199
|
end
|
985
1200
|
end
|
986
1201
|
end
|