pure-patchright 1.62.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patchright/__init__.py +5 -0
- patchright/__main__.py +18 -0
- patchright/_impl/__init__.py +0 -0
- patchright/_impl/__pyinstaller/__init__.py +20 -0
- patchright/_impl/__pyinstaller/hook-playwright.async_api.py +3 -0
- patchright/_impl/__pyinstaller/hook-playwright.sync_api.py +3 -0
- patchright/_impl/_api_structures.py +343 -0
- patchright/_impl/_artifact.py +46 -0
- patchright/_impl/_assertions.py +1014 -0
- patchright/_impl/_async_base.py +88 -0
- patchright/_impl/_browser.py +267 -0
- patchright/_impl/_browser_context.py +759 -0
- patchright/_impl/_browser_type.py +336 -0
- patchright/_impl/_cdp_session.py +25 -0
- patchright/_impl/_clock.py +62 -0
- patchright/_impl/_connection.py +686 -0
- patchright/_impl/_console_message.py +83 -0
- patchright/_impl/_credentials.py +38 -0
- patchright/_impl/_debugger.py +37 -0
- patchright/_impl/_dialog.py +45 -0
- patchright/_impl/_disposable.py +71 -0
- patchright/_impl/_download.py +49 -0
- patchright/_impl/_driver.py +24 -0
- patchright/_impl/_element_handle.py +446 -0
- patchright/_impl/_errors.py +46 -0
- patchright/_impl/_event_context_manager.py +19 -0
- patchright/_impl/_fetch.py +592 -0
- patchright/_impl/_file_chooser.py +42 -0
- patchright/_impl/_form_data.py +19 -0
- patchright/_impl/_frame.py +959 -0
- patchright/_impl/_glob.py +47 -0
- patchright/_impl/_greenlets.py +35 -0
- patchright/_impl/_har_router.py +98 -0
- patchright/_impl/_helper.py +551 -0
- patchright/_impl/_impl_to_api_mapping.py +141 -0
- patchright/_impl/_input.py +85 -0
- patchright/_impl/_js_handle.py +297 -0
- patchright/_impl/_json_pipe.py +55 -0
- patchright/_impl/_local_utils.py +73 -0
- patchright/_impl/_locator.py +894 -0
- patchright/_impl/_map.py +18 -0
- patchright/_impl/_network.py +953 -0
- patchright/_impl/_object_factory.py +93 -0
- patchright/_impl/_page.py +1601 -0
- patchright/_impl/_path_utils.py +13 -0
- patchright/_impl/_playwright.py +43 -0
- patchright/_impl/_screencast.py +149 -0
- patchright/_impl/_selectors.py +48 -0
- patchright/_impl/_set_input_files_helpers.py +134 -0
- patchright/_impl/_str_utils.py +59 -0
- patchright/_impl/_stream.py +31 -0
- patchright/_impl/_sync_base.py +130 -0
- patchright/_impl/_tracing.py +243 -0
- patchright/_impl/_transport.py +151 -0
- patchright/_impl/_video.py +41 -0
- patchright/_impl/_waiter.py +168 -0
- patchright/_impl/_web_error.py +33 -0
- patchright/_impl/_web_storage.py +41 -0
- patchright/_impl/_writable_stream.py +26 -0
- patchright/_repo_version.py +1 -0
- patchright/async_api/__init__.py +234 -0
- patchright/async_api/_context_manager.py +38 -0
- patchright/async_api/_generated.py +23396 -0
- patchright/driver/README.md +1 -0
- patchright/driver/package/README.md +3 -0
- patchright/driver/package/ThirdPartyNotices.txt +13 -0
- patchright/driver/package/bin/install_media_pack.ps1 +5 -0
- patchright/driver/package/bin/install_webkit_wsl.ps1 +33 -0
- patchright/driver/package/bin/reinstall_chrome_beta_linux.sh +42 -0
- patchright/driver/package/bin/reinstall_chrome_beta_mac.sh +13 -0
- patchright/driver/package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- patchright/driver/package/bin/reinstall_chrome_stable_linux.sh +42 -0
- patchright/driver/package/bin/reinstall_chrome_stable_mac.sh +12 -0
- patchright/driver/package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- patchright/driver/package/bin/reinstall_msedge_beta_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_beta_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- patchright/driver/package/bin/reinstall_msedge_dev_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_dev_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- patchright/driver/package/bin/reinstall_msedge_stable_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_stable_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- patchright/driver/package/browsers.json +75 -0
- patchright/driver/package/cli.js +21 -0
- patchright/driver/package/index.js +17 -0
- patchright/driver/package/index.mjs +28 -0
- patchright/driver/package/lib/bootstrap.js +88 -0
- patchright/driver/package/lib/coreBundle.js +77498 -0
- patchright/driver/package/lib/entry/cliDaemon.js +5 -0
- patchright/driver/package/lib/entry/dashboardApp.js +3 -0
- patchright/driver/package/lib/entry/mcp.js +10 -0
- patchright/driver/package/lib/entry/oopBrowserDownload.js +3 -0
- patchright/driver/package/lib/package.js +50 -0
- patchright/driver/package/lib/server/chromium/appIcon.png +0 -0
- patchright/driver/package/lib/server/electron/loader.js +107 -0
- patchright/driver/package/lib/serverRegistry.js +7347 -0
- patchright/driver/package/lib/serverRegistry.js.LICENSE +354 -0
- patchright/driver/package/lib/tools/cli-client/channelSessions.js +141 -0
- patchright/driver/package/lib/tools/cli-client/cli.js +6 -0
- patchright/driver/package/lib/tools/cli-client/help.json +708 -0
- patchright/driver/package/lib/tools/cli-client/minimist.js +128 -0
- patchright/driver/package/lib/tools/cli-client/output.js +343 -0
- patchright/driver/package/lib/tools/cli-client/program.js +404 -0
- patchright/driver/package/lib/tools/cli-client/registry.js +176 -0
- patchright/driver/package/lib/tools/cli-client/session.js +258 -0
- patchright/driver/package/lib/tools/dashboard/appIcon.png +0 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/SKILL.md +420 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/running-code.md +241 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/session-management.md +225 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- patchright/driver/package/lib/tools/skills/playwright-cli/references/video-recording.md +143 -0
- patchright/driver/package/lib/tools/skills/playwright-component-testing/SKILL.md +143 -0
- patchright/driver/package/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- patchright/driver/package/lib/tools/skills/playwright-component-testing/references/migration.md +85 -0
- patchright/driver/package/lib/tools/skills/playwright-component-testing/references/react.md +67 -0
- patchright/driver/package/lib/tools/skills/playwright-component-testing/references/vue.md +75 -0
- patchright/driver/package/lib/tools/skills/playwright-trace/SKILL.md +171 -0
- patchright/driver/package/lib/tools/utils/extension.js +101 -0
- patchright/driver/package/lib/tools/utils/socketConnection.js +108 -0
- patchright/driver/package/lib/utilsBundle.js +90764 -0
- patchright/driver/package/lib/utilsBundle.js.LICENSE +2179 -0
- patchright/driver/package/lib/webp_codec.LICENSE +173 -0
- patchright/driver/package/lib/webp_codec.wasm +0 -0
- patchright/driver/package/lib/xdg-open +1267 -0
- patchright/driver/package/package.json +34 -0
- patchright/py.typed +0 -0
- patchright/sync_api/__init__.py +234 -0
- patchright/sync_api/_context_manager.py +73 -0
- patchright/sync_api/_generated.py +23590 -0
- pure_patchright-1.62.3.dist-info/LICENSE +201 -0
- pure_patchright-1.62.3.dist-info/METADATA +96 -0
- pure_patchright-1.62.3.dist-info/RECORD +142 -0
- pure_patchright-1.62.3.dist-info/WHEEL +4 -0
- pure_patchright-1.62.3.dist-info/entry_points.txt +5 -0
- pure_patchright-1.62.3.dist-info/licenses/LICENSE +202 -0
- pure_patchright-1.62.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import (
|
|
4
|
+
TYPE_CHECKING,
|
|
5
|
+
Any,
|
|
6
|
+
Dict,
|
|
7
|
+
List,
|
|
8
|
+
Literal,
|
|
9
|
+
Optional,
|
|
10
|
+
Pattern,
|
|
11
|
+
Sequence,
|
|
12
|
+
Set,
|
|
13
|
+
Union,
|
|
14
|
+
cast,
|
|
15
|
+
)
|
|
16
|
+
from pyee import EventEmitter
|
|
17
|
+
from patchright._impl._api_structures import (
|
|
18
|
+
AriaRole,
|
|
19
|
+
DropPayload,
|
|
20
|
+
FilePayload,
|
|
21
|
+
FrameExpectOptions,
|
|
22
|
+
FrameExpectResult,
|
|
23
|
+
Position,
|
|
24
|
+
)
|
|
25
|
+
from patchright._impl._connection import (
|
|
26
|
+
ChannelOwner,
|
|
27
|
+
from_channel,
|
|
28
|
+
from_nullable_channel,
|
|
29
|
+
)
|
|
30
|
+
from patchright._impl._element_handle import ElementHandle, convert_select_option_values
|
|
31
|
+
from patchright._impl._errors import Error
|
|
32
|
+
from patchright._impl._event_context_manager import EventContextManagerImpl
|
|
33
|
+
from patchright._impl._helper import (
|
|
34
|
+
DocumentLoadState,
|
|
35
|
+
FrameNavigatedEvent,
|
|
36
|
+
KeyboardModifier,
|
|
37
|
+
MouseButton,
|
|
38
|
+
TimeoutSettings,
|
|
39
|
+
URLMatch,
|
|
40
|
+
async_readfile,
|
|
41
|
+
locals_to_params,
|
|
42
|
+
monotonic_time,
|
|
43
|
+
url_matches,
|
|
44
|
+
)
|
|
45
|
+
from patchright._impl._js_handle import (
|
|
46
|
+
JSHandle,
|
|
47
|
+
Serializable,
|
|
48
|
+
add_source_url_to_script,
|
|
49
|
+
parse_result,
|
|
50
|
+
parse_value,
|
|
51
|
+
serialize_argument,
|
|
52
|
+
)
|
|
53
|
+
from patchright._impl._locator import (
|
|
54
|
+
FrameLocator,
|
|
55
|
+
Locator,
|
|
56
|
+
get_by_alt_text_selector,
|
|
57
|
+
get_by_label_selector,
|
|
58
|
+
get_by_placeholder_selector,
|
|
59
|
+
get_by_role_selector,
|
|
60
|
+
get_by_test_id_selector,
|
|
61
|
+
get_by_text_selector,
|
|
62
|
+
get_by_title_selector,
|
|
63
|
+
test_id_attribute_name,
|
|
64
|
+
)
|
|
65
|
+
from patchright._impl._network import Response
|
|
66
|
+
from patchright._impl._set_input_files_helpers import convert_input_files
|
|
67
|
+
from patchright._impl._waiter import Waiter
|
|
68
|
+
|
|
69
|
+
if TYPE_CHECKING:
|
|
70
|
+
from patchright._impl._page import Page
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Frame(ChannelOwner):
|
|
74
|
+
def __init__(
|
|
75
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
76
|
+
) -> None:
|
|
77
|
+
super().__init__(parent, type, guid, initializer)
|
|
78
|
+
self._parent_frame = from_nullable_channel(initializer.get("parentFrame"))
|
|
79
|
+
if self._parent_frame:
|
|
80
|
+
self._parent_frame._child_frames.append(self)
|
|
81
|
+
self._name = initializer["name"]
|
|
82
|
+
self._url = initializer["url"]
|
|
83
|
+
self._detached = False
|
|
84
|
+
self._child_frames: List[Frame] = []
|
|
85
|
+
self._page: Optional[Page] = None
|
|
86
|
+
self._load_states: Set[str] = set(initializer["loadStates"])
|
|
87
|
+
self._event_emitter = EventEmitter()
|
|
88
|
+
self._channel.on(
|
|
89
|
+
"loadstate",
|
|
90
|
+
lambda params: self._on_load_state(params.get("add"), params.get("remove")),
|
|
91
|
+
)
|
|
92
|
+
self._channel.on("navigated", lambda params: self._on_frame_navigated(params))
|
|
93
|
+
|
|
94
|
+
def __repr__(self) -> str:
|
|
95
|
+
return f"<Frame name={self.name} url={self.url!r}>"
|
|
96
|
+
|
|
97
|
+
def _on_load_state(
|
|
98
|
+
self, add: DocumentLoadState = None, remove: DocumentLoadState = None
|
|
99
|
+
) -> None:
|
|
100
|
+
if add:
|
|
101
|
+
self._load_states.add(add)
|
|
102
|
+
self._event_emitter.emit("loadstate", add)
|
|
103
|
+
elif remove and remove in self._load_states:
|
|
104
|
+
self._load_states.remove(remove)
|
|
105
|
+
if not self._parent_frame and add == "load" and self._page:
|
|
106
|
+
self._page.emit("load", self._page)
|
|
107
|
+
self._page.context.emit("pageload", self._page)
|
|
108
|
+
if not self._parent_frame and add == "domcontentloaded" and self._page:
|
|
109
|
+
self._page.emit("domcontentloaded", self._page)
|
|
110
|
+
|
|
111
|
+
def _on_frame_navigated(self, event: FrameNavigatedEvent) -> None:
|
|
112
|
+
self._url = event["url"]
|
|
113
|
+
self._name = event["name"]
|
|
114
|
+
self._event_emitter.emit("navigated", event)
|
|
115
|
+
if "error" not in event and self._page:
|
|
116
|
+
self._page.emit("framenavigated", self)
|
|
117
|
+
self._page.context.emit("framenavigated", self)
|
|
118
|
+
|
|
119
|
+
async def _query_count(self, selector: str) -> int:
|
|
120
|
+
return await self._channel.send("queryCount", None, {"selector": selector})
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def page(self) -> "Page":
|
|
124
|
+
assert self._page
|
|
125
|
+
return self._page
|
|
126
|
+
|
|
127
|
+
async def goto(
|
|
128
|
+
self,
|
|
129
|
+
url: str,
|
|
130
|
+
timeout: float = None,
|
|
131
|
+
waitUntil: DocumentLoadState = None,
|
|
132
|
+
referer: str = None,
|
|
133
|
+
) -> Optional[Response]:
|
|
134
|
+
return cast(
|
|
135
|
+
Optional[Response],
|
|
136
|
+
from_nullable_channel(
|
|
137
|
+
await self._channel.send(
|
|
138
|
+
"goto", self._navigation_timeout, locals_to_params(locals())
|
|
139
|
+
)
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def _setup_navigation_waiter(self, wait_name: str, timeout: float = None) -> Waiter:
|
|
144
|
+
assert self._page
|
|
145
|
+
waiter = Waiter(self._page, f"frame.{wait_name}")
|
|
146
|
+
waiter.reject_on_event(
|
|
147
|
+
self._page,
|
|
148
|
+
"close",
|
|
149
|
+
lambda: cast("Page", self._page)._close_error_with_reason(),
|
|
150
|
+
)
|
|
151
|
+
waiter.reject_on_event(
|
|
152
|
+
self._page, "crash", Error("Navigation failed because page crashed!")
|
|
153
|
+
)
|
|
154
|
+
waiter.reject_on_event(
|
|
155
|
+
self._page,
|
|
156
|
+
"framedetached",
|
|
157
|
+
Error("Navigating frame was detached!"),
|
|
158
|
+
lambda frame: frame == self,
|
|
159
|
+
)
|
|
160
|
+
timeout = self._page._timeout_settings.navigation_timeout(timeout)
|
|
161
|
+
waiter.reject_on_timeout(timeout, f"Timeout {timeout}ms exceeded.")
|
|
162
|
+
return waiter
|
|
163
|
+
|
|
164
|
+
async def _expect(
|
|
165
|
+
self,
|
|
166
|
+
selector: Optional[str],
|
|
167
|
+
expression: str,
|
|
168
|
+
options: FrameExpectOptions,
|
|
169
|
+
title: str = None,
|
|
170
|
+
) -> FrameExpectResult:
|
|
171
|
+
if "expectedValue" in options:
|
|
172
|
+
options["expectedValue"] = serialize_argument(options["expectedValue"])
|
|
173
|
+
try:
|
|
174
|
+
await self._channel.send(
|
|
175
|
+
"expect",
|
|
176
|
+
self._timeout,
|
|
177
|
+
{"selector": selector, "expression": expression, **options},
|
|
178
|
+
title=title,
|
|
179
|
+
)
|
|
180
|
+
return {"matches": not options.get("isNot")}
|
|
181
|
+
except Error as e:
|
|
182
|
+
if not e._details:
|
|
183
|
+
raise e
|
|
184
|
+
details = cast(Dict[str, Any], e._details)
|
|
185
|
+
received = details.get("received")
|
|
186
|
+
if received:
|
|
187
|
+
received = {
|
|
188
|
+
"value": parse_value(received["value"])
|
|
189
|
+
if "value" in received
|
|
190
|
+
else None,
|
|
191
|
+
"ariaSnapshot": received.get("ariaSnapshot"),
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
"matches": bool(options.get("isNot")),
|
|
195
|
+
"received": received,
|
|
196
|
+
"timedOut": details.get("timedOut"),
|
|
197
|
+
"errorMessage": "Error: " + details["customErrorMessage"]
|
|
198
|
+
if details.get("customErrorMessage")
|
|
199
|
+
else None,
|
|
200
|
+
"log": e._log,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
def expect_navigation(
|
|
204
|
+
self,
|
|
205
|
+
url: URLMatch = None,
|
|
206
|
+
waitUntil: DocumentLoadState = None,
|
|
207
|
+
timeout: float = None,
|
|
208
|
+
) -> EventContextManagerImpl[Response]:
|
|
209
|
+
assert self._page
|
|
210
|
+
if not waitUntil:
|
|
211
|
+
waitUntil = "load"
|
|
212
|
+
if timeout is None:
|
|
213
|
+
timeout = self._page._timeout_settings.navigation_timeout()
|
|
214
|
+
deadline = monotonic_time() + timeout
|
|
215
|
+
waiter = self._setup_navigation_waiter("expect_navigation", timeout)
|
|
216
|
+
to_url = f' to "{url}"' if url else ""
|
|
217
|
+
waiter.log(f"waiting for navigation{to_url} until '{waitUntil}'")
|
|
218
|
+
|
|
219
|
+
def predicate(event: Any) -> bool:
|
|
220
|
+
if event.get("error"):
|
|
221
|
+
return True
|
|
222
|
+
waiter.log(f''' navigated to "{event["url"]}"''')
|
|
223
|
+
return url_matches(
|
|
224
|
+
cast("Page", self._page)._browser_context._base_url, event["url"], url
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
waiter.wait_for_event(self._event_emitter, "navigated", predicate=predicate)
|
|
228
|
+
|
|
229
|
+
async def continuation() -> Optional[Response]:
|
|
230
|
+
event = await waiter.result()
|
|
231
|
+
if "error" in event:
|
|
232
|
+
raise Error(event["error"])
|
|
233
|
+
if waitUntil not in self._load_states:
|
|
234
|
+
t = deadline - monotonic_time()
|
|
235
|
+
if t > 0:
|
|
236
|
+
await self._wait_for_load_state_impl(state=waitUntil, timeout=t)
|
|
237
|
+
if "newDocument" in event and "request" in event["newDocument"]:
|
|
238
|
+
request = from_channel(event["newDocument"]["request"])
|
|
239
|
+
return await request.response()
|
|
240
|
+
return None
|
|
241
|
+
|
|
242
|
+
return EventContextManagerImpl(asyncio.create_task(continuation()))
|
|
243
|
+
|
|
244
|
+
async def wait_for_url(
|
|
245
|
+
self, url: URLMatch, waitUntil: DocumentLoadState = None, timeout: float = None
|
|
246
|
+
) -> None:
|
|
247
|
+
assert self._page
|
|
248
|
+
if url_matches(self._page._browser_context._base_url, self.url, url):
|
|
249
|
+
await self._wait_for_load_state_impl(state=waitUntil, timeout=timeout)
|
|
250
|
+
return
|
|
251
|
+
try:
|
|
252
|
+
async with self.expect_navigation(
|
|
253
|
+
url=url, waitUntil=waitUntil, timeout=timeout
|
|
254
|
+
):
|
|
255
|
+
pass
|
|
256
|
+
except Exception:
|
|
257
|
+
if url_matches(self._page._browser_context._base_url, self.url, url):
|
|
258
|
+
await self._wait_for_load_state_impl(state=waitUntil, timeout=timeout)
|
|
259
|
+
return
|
|
260
|
+
raise
|
|
261
|
+
|
|
262
|
+
async def wait_for_load_state(
|
|
263
|
+
self,
|
|
264
|
+
state: Literal["domcontentloaded", "load", "networkidle"] = None,
|
|
265
|
+
timeout: float = None,
|
|
266
|
+
) -> None:
|
|
267
|
+
return await self._wait_for_load_state_impl(state, timeout)
|
|
268
|
+
|
|
269
|
+
async def _wait_for_load_state_impl(
|
|
270
|
+
self, state: DocumentLoadState = None, timeout: float = None
|
|
271
|
+
) -> None:
|
|
272
|
+
if not state:
|
|
273
|
+
state = "load"
|
|
274
|
+
if state not in ("load", "domcontentloaded", "networkidle", "commit"):
|
|
275
|
+
raise Error(
|
|
276
|
+
"state: expected one of (load|domcontentloaded|networkidle|commit)"
|
|
277
|
+
)
|
|
278
|
+
waiter = self._setup_navigation_waiter("wait_for_load_state", timeout)
|
|
279
|
+
if state in self._load_states:
|
|
280
|
+
waiter.log(f' not waiting, "{state}" event already fired')
|
|
281
|
+
waiter._fulfill(None)
|
|
282
|
+
else:
|
|
283
|
+
|
|
284
|
+
def handle_load_state_event(actual_state: str) -> bool:
|
|
285
|
+
waiter.log(f'"{actual_state}" event fired')
|
|
286
|
+
return actual_state == state
|
|
287
|
+
|
|
288
|
+
waiter.wait_for_event(
|
|
289
|
+
self._event_emitter, "loadstate", handle_load_state_event
|
|
290
|
+
)
|
|
291
|
+
await waiter.result()
|
|
292
|
+
|
|
293
|
+
def _timeout(self, timeout: Optional[float]) -> float:
|
|
294
|
+
timeout_settings = (
|
|
295
|
+
self._page._timeout_settings if self._page else TimeoutSettings(None)
|
|
296
|
+
)
|
|
297
|
+
return timeout_settings.timeout(timeout)
|
|
298
|
+
|
|
299
|
+
def _navigation_timeout(self, timeout: Optional[float]) -> float:
|
|
300
|
+
timeout_settings = (
|
|
301
|
+
self._page._timeout_settings if self._page else TimeoutSettings(None)
|
|
302
|
+
)
|
|
303
|
+
return timeout_settings.navigation_timeout(timeout)
|
|
304
|
+
|
|
305
|
+
async def frame_element(self) -> ElementHandle:
|
|
306
|
+
return from_channel(await self._channel.send("frameElement", None))
|
|
307
|
+
|
|
308
|
+
async def evaluate(
|
|
309
|
+
self,
|
|
310
|
+
expression: str,
|
|
311
|
+
arg: Serializable = None,
|
|
312
|
+
*,
|
|
313
|
+
isolatedContext: Optional[bool] = True,
|
|
314
|
+
) -> Any:
|
|
315
|
+
return parse_result(
|
|
316
|
+
await self._channel.send(
|
|
317
|
+
"evaluateExpression",
|
|
318
|
+
None,
|
|
319
|
+
dict(
|
|
320
|
+
expression=expression,
|
|
321
|
+
arg=serialize_argument(arg),
|
|
322
|
+
isolatedContext=isolatedContext,
|
|
323
|
+
),
|
|
324
|
+
)
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
async def evaluate_handle(
|
|
328
|
+
self,
|
|
329
|
+
expression: str,
|
|
330
|
+
arg: Serializable = None,
|
|
331
|
+
*,
|
|
332
|
+
isolatedContext: Optional[bool] = True,
|
|
333
|
+
) -> JSHandle:
|
|
334
|
+
return from_channel(
|
|
335
|
+
await self._channel.send(
|
|
336
|
+
"evaluateExpressionHandle",
|
|
337
|
+
None,
|
|
338
|
+
dict(
|
|
339
|
+
expression=expression,
|
|
340
|
+
arg=serialize_argument(arg),
|
|
341
|
+
isolatedContext=isolatedContext,
|
|
342
|
+
),
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
async def query_selector(
|
|
347
|
+
self, selector: str, strict: bool = None
|
|
348
|
+
) -> Optional[ElementHandle]:
|
|
349
|
+
return from_nullable_channel(
|
|
350
|
+
await self._channel.send("querySelector", None, locals_to_params(locals()))
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
async def query_selector_all(self, selector: str) -> List[ElementHandle]:
|
|
354
|
+
return list(
|
|
355
|
+
map(
|
|
356
|
+
from_channel,
|
|
357
|
+
await self._channel.send(
|
|
358
|
+
"querySelectorAll", None, dict(selector=selector)
|
|
359
|
+
),
|
|
360
|
+
)
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
async def wait_for_selector(
|
|
364
|
+
self,
|
|
365
|
+
selector: str,
|
|
366
|
+
strict: bool = None,
|
|
367
|
+
timeout: float = None,
|
|
368
|
+
state: Literal["attached", "detached", "hidden", "visible"] = None,
|
|
369
|
+
) -> Optional[ElementHandle]:
|
|
370
|
+
return from_nullable_channel(
|
|
371
|
+
await self._channel.send(
|
|
372
|
+
"waitForSelector", self._timeout, locals_to_params(locals())
|
|
373
|
+
)
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
async def is_checked(
|
|
377
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
378
|
+
) -> bool:
|
|
379
|
+
return await self._channel.send(
|
|
380
|
+
"isChecked", self._timeout, locals_to_params(locals())
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
async def is_disabled(
|
|
384
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
385
|
+
) -> bool:
|
|
386
|
+
return await self._channel.send(
|
|
387
|
+
"isDisabled", self._timeout, locals_to_params(locals())
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
async def is_editable(
|
|
391
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
392
|
+
) -> bool:
|
|
393
|
+
return await self._channel.send(
|
|
394
|
+
"isEditable", self._timeout, locals_to_params(locals())
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
async def is_enabled(
|
|
398
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
399
|
+
) -> bool:
|
|
400
|
+
return await self._channel.send(
|
|
401
|
+
"isEnabled", self._timeout, locals_to_params(locals())
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
async def is_hidden(self, selector: str, strict: bool = None) -> bool:
|
|
405
|
+
return await self._channel.send(
|
|
406
|
+
"isHidden", self._timeout, locals_to_params(locals())
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
async def is_visible(self, selector: str, strict: bool = None) -> bool:
|
|
410
|
+
return await self._channel.send(
|
|
411
|
+
"isVisible", self._timeout, locals_to_params(locals())
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
async def dispatch_event(
|
|
415
|
+
self,
|
|
416
|
+
selector: str,
|
|
417
|
+
type: str,
|
|
418
|
+
eventInit: Dict = None,
|
|
419
|
+
strict: bool = None,
|
|
420
|
+
timeout: float = None,
|
|
421
|
+
) -> None:
|
|
422
|
+
await self._channel.send(
|
|
423
|
+
"dispatchEvent",
|
|
424
|
+
self._timeout,
|
|
425
|
+
locals_to_params(
|
|
426
|
+
dict(
|
|
427
|
+
selector=selector,
|
|
428
|
+
type=type,
|
|
429
|
+
eventInit=serialize_argument(eventInit),
|
|
430
|
+
strict=strict,
|
|
431
|
+
timeout=timeout,
|
|
432
|
+
)
|
|
433
|
+
),
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
async def eval_on_selector(
|
|
437
|
+
self,
|
|
438
|
+
selector: str,
|
|
439
|
+
expression: str,
|
|
440
|
+
arg: Serializable = None,
|
|
441
|
+
strict: bool = None,
|
|
442
|
+
) -> Any:
|
|
443
|
+
return parse_result(
|
|
444
|
+
await self._channel.send(
|
|
445
|
+
"evalOnSelector",
|
|
446
|
+
None,
|
|
447
|
+
locals_to_params(
|
|
448
|
+
dict(
|
|
449
|
+
selector=selector,
|
|
450
|
+
expression=expression,
|
|
451
|
+
arg=serialize_argument(arg),
|
|
452
|
+
strict=strict,
|
|
453
|
+
)
|
|
454
|
+
),
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
async def eval_on_selector_all(
|
|
459
|
+
self,
|
|
460
|
+
selector: str,
|
|
461
|
+
expression: str,
|
|
462
|
+
arg: Serializable = None,
|
|
463
|
+
*,
|
|
464
|
+
isolatedContext: Optional[bool] = True,
|
|
465
|
+
) -> Any:
|
|
466
|
+
return parse_result(
|
|
467
|
+
await self._channel.send(
|
|
468
|
+
"evalOnSelectorAll",
|
|
469
|
+
None,
|
|
470
|
+
dict(
|
|
471
|
+
selector=selector,
|
|
472
|
+
expression=expression,
|
|
473
|
+
arg=serialize_argument(arg),
|
|
474
|
+
isolatedContext=isolatedContext,
|
|
475
|
+
),
|
|
476
|
+
)
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
async def content(self) -> str:
|
|
480
|
+
return await self._channel.send("content", None)
|
|
481
|
+
|
|
482
|
+
async def set_content(
|
|
483
|
+
self, html: str, timeout: float = None, waitUntil: DocumentLoadState = None
|
|
484
|
+
) -> None:
|
|
485
|
+
await self._channel.send(
|
|
486
|
+
"setContent", self._navigation_timeout, locals_to_params(locals())
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
@property
|
|
490
|
+
def name(self) -> str:
|
|
491
|
+
return self._name or ""
|
|
492
|
+
|
|
493
|
+
@property
|
|
494
|
+
def url(self) -> str:
|
|
495
|
+
return self._url or ""
|
|
496
|
+
|
|
497
|
+
@property
|
|
498
|
+
def parent_frame(self) -> Optional["Frame"]:
|
|
499
|
+
return self._parent_frame
|
|
500
|
+
|
|
501
|
+
@property
|
|
502
|
+
def child_frames(self) -> List["Frame"]:
|
|
503
|
+
return self._child_frames.copy()
|
|
504
|
+
|
|
505
|
+
def is_detached(self) -> bool:
|
|
506
|
+
return self._detached
|
|
507
|
+
|
|
508
|
+
async def add_script_tag(
|
|
509
|
+
self,
|
|
510
|
+
url: str = None,
|
|
511
|
+
path: Union[str, Path] = None,
|
|
512
|
+
content: str = None,
|
|
513
|
+
type: str = None,
|
|
514
|
+
) -> ElementHandle:
|
|
515
|
+
params = locals_to_params(locals())
|
|
516
|
+
if path:
|
|
517
|
+
params["content"] = add_source_url_to_script(
|
|
518
|
+
(await async_readfile(path)).decode(), path
|
|
519
|
+
)
|
|
520
|
+
del params["path"]
|
|
521
|
+
return from_channel(await self._channel.send("addScriptTag", None, params))
|
|
522
|
+
|
|
523
|
+
async def add_style_tag(
|
|
524
|
+
self, url: str = None, path: Union[str, Path] = None, content: str = None
|
|
525
|
+
) -> ElementHandle:
|
|
526
|
+
params = locals_to_params(locals())
|
|
527
|
+
if path:
|
|
528
|
+
params["content"] = (
|
|
529
|
+
(await async_readfile(path)).decode()
|
|
530
|
+
+ "\n/*# sourceURL="
|
|
531
|
+
+ str(Path(path))
|
|
532
|
+
+ "*/"
|
|
533
|
+
)
|
|
534
|
+
del params["path"]
|
|
535
|
+
return from_channel(await self._channel.send("addStyleTag", None, params))
|
|
536
|
+
|
|
537
|
+
async def click(
|
|
538
|
+
self,
|
|
539
|
+
selector: str,
|
|
540
|
+
modifiers: Sequence[KeyboardModifier] = None,
|
|
541
|
+
position: Position = None,
|
|
542
|
+
delay: float = None,
|
|
543
|
+
button: MouseButton = None,
|
|
544
|
+
clickCount: int = None,
|
|
545
|
+
timeout: float = None,
|
|
546
|
+
force: bool = None,
|
|
547
|
+
noWaitAfter: bool = None,
|
|
548
|
+
strict: bool = None,
|
|
549
|
+
trial: bool = None,
|
|
550
|
+
scroll: Literal["auto", "none"] = None,
|
|
551
|
+
) -> None:
|
|
552
|
+
await self._click(**locals_to_params(locals()))
|
|
553
|
+
|
|
554
|
+
async def _click(
|
|
555
|
+
self,
|
|
556
|
+
selector: str,
|
|
557
|
+
modifiers: Sequence[KeyboardModifier] = None,
|
|
558
|
+
position: Position = None,
|
|
559
|
+
delay: float = None,
|
|
560
|
+
button: MouseButton = None,
|
|
561
|
+
clickCount: int = None,
|
|
562
|
+
timeout: float = None,
|
|
563
|
+
force: bool = None,
|
|
564
|
+
noWaitAfter: bool = None,
|
|
565
|
+
strict: bool = None,
|
|
566
|
+
trial: bool = None,
|
|
567
|
+
steps: int = None,
|
|
568
|
+
scroll: Literal["auto", "none"] = None,
|
|
569
|
+
) -> None:
|
|
570
|
+
await self._channel.send("click", self._timeout, locals_to_params(locals()))
|
|
571
|
+
|
|
572
|
+
async def dblclick(
|
|
573
|
+
self,
|
|
574
|
+
selector: str,
|
|
575
|
+
modifiers: Sequence[KeyboardModifier] = None,
|
|
576
|
+
position: Position = None,
|
|
577
|
+
delay: float = None,
|
|
578
|
+
button: MouseButton = None,
|
|
579
|
+
timeout: float = None,
|
|
580
|
+
force: bool = None,
|
|
581
|
+
noWaitAfter: bool = None,
|
|
582
|
+
strict: bool = None,
|
|
583
|
+
trial: bool = None,
|
|
584
|
+
scroll: Literal["auto", "none"] = None,
|
|
585
|
+
) -> None:
|
|
586
|
+
await self._channel.send(
|
|
587
|
+
"dblclick", self._timeout, locals_to_params(locals()), title="Double click"
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
async def tap(
|
|
591
|
+
self,
|
|
592
|
+
selector: str,
|
|
593
|
+
modifiers: Sequence[KeyboardModifier] = None,
|
|
594
|
+
position: Position = None,
|
|
595
|
+
timeout: float = None,
|
|
596
|
+
force: bool = None,
|
|
597
|
+
noWaitAfter: bool = None,
|
|
598
|
+
strict: bool = None,
|
|
599
|
+
trial: bool = None,
|
|
600
|
+
scroll: Literal["auto", "none"] = None,
|
|
601
|
+
) -> None:
|
|
602
|
+
await self._channel.send("tap", self._timeout, locals_to_params(locals()))
|
|
603
|
+
|
|
604
|
+
async def fill(
|
|
605
|
+
self,
|
|
606
|
+
selector: str,
|
|
607
|
+
value: str,
|
|
608
|
+
timeout: float = None,
|
|
609
|
+
noWaitAfter: bool = None,
|
|
610
|
+
strict: bool = None,
|
|
611
|
+
force: bool = None,
|
|
612
|
+
) -> None:
|
|
613
|
+
await self._fill(**locals_to_params(locals()))
|
|
614
|
+
|
|
615
|
+
async def _fill(
|
|
616
|
+
self,
|
|
617
|
+
selector: str,
|
|
618
|
+
value: str,
|
|
619
|
+
timeout: float = None,
|
|
620
|
+
noWaitAfter: bool = None,
|
|
621
|
+
strict: bool = None,
|
|
622
|
+
force: bool = None,
|
|
623
|
+
title: str = None,
|
|
624
|
+
) -> None:
|
|
625
|
+
await self._channel.send("fill", self._timeout, locals_to_params(locals()))
|
|
626
|
+
|
|
627
|
+
def locator(
|
|
628
|
+
self,
|
|
629
|
+
selector: str,
|
|
630
|
+
hasText: Union[str, Pattern[str]] = None,
|
|
631
|
+
hasNotText: Union[str, Pattern[str]] = None,
|
|
632
|
+
has: Locator = None,
|
|
633
|
+
hasNot: Locator = None,
|
|
634
|
+
) -> Locator:
|
|
635
|
+
return Locator(
|
|
636
|
+
self,
|
|
637
|
+
selector,
|
|
638
|
+
has_text=hasText,
|
|
639
|
+
has_not_text=hasNotText,
|
|
640
|
+
has=has,
|
|
641
|
+
has_not=hasNot,
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
def get_by_alt_text(
|
|
645
|
+
self, text: Union[str, Pattern[str]], exact: bool = None
|
|
646
|
+
) -> "Locator":
|
|
647
|
+
return self.locator(get_by_alt_text_selector(text, exact=exact))
|
|
648
|
+
|
|
649
|
+
def get_by_label(
|
|
650
|
+
self, text: Union[str, Pattern[str]], exact: bool = None
|
|
651
|
+
) -> "Locator":
|
|
652
|
+
return self.locator(get_by_label_selector(text, exact=exact))
|
|
653
|
+
|
|
654
|
+
def get_by_placeholder(
|
|
655
|
+
self, text: Union[str, Pattern[str]], exact: bool = None
|
|
656
|
+
) -> "Locator":
|
|
657
|
+
return self.locator(get_by_placeholder_selector(text, exact=exact))
|
|
658
|
+
|
|
659
|
+
def get_by_role(
|
|
660
|
+
self,
|
|
661
|
+
role: AriaRole,
|
|
662
|
+
checked: bool = None,
|
|
663
|
+
disabled: bool = None,
|
|
664
|
+
expanded: bool = None,
|
|
665
|
+
includeHidden: bool = None,
|
|
666
|
+
level: int = None,
|
|
667
|
+
name: Union[str, Pattern[str]] = None,
|
|
668
|
+
pressed: bool = None,
|
|
669
|
+
selected: bool = None,
|
|
670
|
+
exact: bool = None,
|
|
671
|
+
description: Union[str, Pattern[str]] = None,
|
|
672
|
+
) -> "Locator":
|
|
673
|
+
return self.locator(
|
|
674
|
+
get_by_role_selector(
|
|
675
|
+
role,
|
|
676
|
+
checked=checked,
|
|
677
|
+
disabled=disabled,
|
|
678
|
+
expanded=expanded,
|
|
679
|
+
includeHidden=includeHidden,
|
|
680
|
+
level=level,
|
|
681
|
+
name=name,
|
|
682
|
+
pressed=pressed,
|
|
683
|
+
selected=selected,
|
|
684
|
+
exact=exact,
|
|
685
|
+
description=description,
|
|
686
|
+
)
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
def get_by_test_id(self, testId: Union[str, Pattern[str]]) -> "Locator":
|
|
690
|
+
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))
|
|
691
|
+
|
|
692
|
+
def get_by_text(
|
|
693
|
+
self, text: Union[str, Pattern[str]], exact: bool = None
|
|
694
|
+
) -> "Locator":
|
|
695
|
+
return self.locator(get_by_text_selector(text, exact=exact))
|
|
696
|
+
|
|
697
|
+
def get_by_title(
|
|
698
|
+
self, text: Union[str, Pattern[str]], exact: bool = None
|
|
699
|
+
) -> "Locator":
|
|
700
|
+
return self.locator(get_by_title_selector(text, exact=exact))
|
|
701
|
+
|
|
702
|
+
def frame_locator(self, selector: str) -> FrameLocator:
|
|
703
|
+
return FrameLocator(self, selector)
|
|
704
|
+
|
|
705
|
+
async def focus(
|
|
706
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
707
|
+
) -> None:
|
|
708
|
+
await self._channel.send("focus", self._timeout, locals_to_params(locals()))
|
|
709
|
+
|
|
710
|
+
async def text_content(
|
|
711
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
712
|
+
) -> Optional[str]:
|
|
713
|
+
return await self._channel.send(
|
|
714
|
+
"textContent", self._timeout, locals_to_params(locals())
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
async def inner_text(
|
|
718
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
719
|
+
) -> str:
|
|
720
|
+
return await self._channel.send(
|
|
721
|
+
"innerText", self._timeout, locals_to_params(locals())
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
async def inner_html(
|
|
725
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
726
|
+
) -> str:
|
|
727
|
+
return await self._channel.send(
|
|
728
|
+
"innerHTML", self._timeout, locals_to_params(locals())
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
async def get_attribute(
|
|
732
|
+
self, selector: str, name: str, strict: bool = None, timeout: float = None
|
|
733
|
+
) -> Optional[str]:
|
|
734
|
+
return await self._channel.send(
|
|
735
|
+
"getAttribute", self._timeout, locals_to_params(locals())
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
async def hover(
|
|
739
|
+
self,
|
|
740
|
+
selector: str,
|
|
741
|
+
modifiers: Sequence[KeyboardModifier] = None,
|
|
742
|
+
position: Position = None,
|
|
743
|
+
timeout: float = None,
|
|
744
|
+
noWaitAfter: bool = None,
|
|
745
|
+
force: bool = None,
|
|
746
|
+
strict: bool = None,
|
|
747
|
+
trial: bool = None,
|
|
748
|
+
scroll: Literal["auto", "none"] = None,
|
|
749
|
+
) -> None:
|
|
750
|
+
await self._channel.send("hover", self._timeout, locals_to_params(locals()))
|
|
751
|
+
|
|
752
|
+
async def drag_and_drop(
|
|
753
|
+
self,
|
|
754
|
+
source: str,
|
|
755
|
+
target: str,
|
|
756
|
+
sourcePosition: Position = None,
|
|
757
|
+
targetPosition: Position = None,
|
|
758
|
+
force: bool = None,
|
|
759
|
+
noWaitAfter: bool = None,
|
|
760
|
+
strict: bool = None,
|
|
761
|
+
timeout: float = None,
|
|
762
|
+
trial: bool = None,
|
|
763
|
+
steps: int = None,
|
|
764
|
+
scroll: Literal["auto", "none"] = None,
|
|
765
|
+
) -> None:
|
|
766
|
+
await self._channel.send(
|
|
767
|
+
"dragAndDrop", self._timeout, locals_to_params(locals())
|
|
768
|
+
)
|
|
769
|
+
|
|
770
|
+
async def select_option(
|
|
771
|
+
self,
|
|
772
|
+
selector: str,
|
|
773
|
+
value: Union[str, Sequence[str]] = None,
|
|
774
|
+
index: Union[int, Sequence[int]] = None,
|
|
775
|
+
label: Union[str, Sequence[str]] = None,
|
|
776
|
+
element: Union["ElementHandle", Sequence["ElementHandle"]] = None,
|
|
777
|
+
timeout: float = None,
|
|
778
|
+
noWaitAfter: bool = None,
|
|
779
|
+
strict: bool = None,
|
|
780
|
+
force: bool = None,
|
|
781
|
+
) -> List[str]:
|
|
782
|
+
params = locals_to_params(
|
|
783
|
+
dict(
|
|
784
|
+
selector=selector,
|
|
785
|
+
timeout=timeout,
|
|
786
|
+
strict=strict,
|
|
787
|
+
force=force,
|
|
788
|
+
**convert_select_option_values(value, index, label, element),
|
|
789
|
+
)
|
|
790
|
+
)
|
|
791
|
+
return await self._channel.send("selectOption", self._timeout, params)
|
|
792
|
+
|
|
793
|
+
async def input_value(
|
|
794
|
+
self, selector: str, strict: bool = None, timeout: float = None
|
|
795
|
+
) -> str:
|
|
796
|
+
return await self._channel.send(
|
|
797
|
+
"inputValue", self._timeout, locals_to_params(locals())
|
|
798
|
+
)
|
|
799
|
+
|
|
800
|
+
async def set_input_files(
|
|
801
|
+
self,
|
|
802
|
+
selector: str,
|
|
803
|
+
files: Union[
|
|
804
|
+
str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload]
|
|
805
|
+
],
|
|
806
|
+
strict: bool = None,
|
|
807
|
+
timeout: float = None,
|
|
808
|
+
noWaitAfter: bool = None,
|
|
809
|
+
) -> None:
|
|
810
|
+
converted = await convert_input_files(files, self.page.context)
|
|
811
|
+
await self._channel.send(
|
|
812
|
+
"setInputFiles",
|
|
813
|
+
self._timeout,
|
|
814
|
+
{
|
|
815
|
+
"selector": selector,
|
|
816
|
+
"strict": strict,
|
|
817
|
+
"timeout": self._timeout(timeout),
|
|
818
|
+
**converted,
|
|
819
|
+
},
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
async def _drop(
|
|
823
|
+
self,
|
|
824
|
+
selector: str,
|
|
825
|
+
payload: "DropPayload",
|
|
826
|
+
strict: bool = None,
|
|
827
|
+
position: Position = None,
|
|
828
|
+
timeout: float = None,
|
|
829
|
+
) -> None:
|
|
830
|
+
params: Dict[str, Any] = {
|
|
831
|
+
"selector": selector,
|
|
832
|
+
"strict": strict,
|
|
833
|
+
"position": position,
|
|
834
|
+
"timeout": self._timeout(timeout),
|
|
835
|
+
}
|
|
836
|
+
files = payload.get("files") if payload else None
|
|
837
|
+
if files is not None:
|
|
838
|
+
converted = await convert_input_files(files, self.page.context)
|
|
839
|
+
if "directoryStream" in converted or "directoryLocalPath" in converted:
|
|
840
|
+
raise Error(
|
|
841
|
+
"Dropping a directory is not supported, pass individual files instead."
|
|
842
|
+
)
|
|
843
|
+
params.update(converted)
|
|
844
|
+
data = payload.get("data") if payload else None
|
|
845
|
+
if data is not None:
|
|
846
|
+
params["data"] = [{"mimeType": k, "value": v} for k, v in data.items()]
|
|
847
|
+
await self._channel.send("drop", self._timeout, params)
|
|
848
|
+
|
|
849
|
+
async def type(
|
|
850
|
+
self,
|
|
851
|
+
selector: str,
|
|
852
|
+
text: str,
|
|
853
|
+
delay: float = None,
|
|
854
|
+
strict: bool = None,
|
|
855
|
+
timeout: float = None,
|
|
856
|
+
noWaitAfter: bool = None,
|
|
857
|
+
) -> None:
|
|
858
|
+
await self._channel.send("type", self._timeout, locals_to_params(locals()))
|
|
859
|
+
|
|
860
|
+
async def press(
|
|
861
|
+
self,
|
|
862
|
+
selector: str,
|
|
863
|
+
key: str,
|
|
864
|
+
delay: float = None,
|
|
865
|
+
strict: bool = None,
|
|
866
|
+
timeout: float = None,
|
|
867
|
+
noWaitAfter: bool = None,
|
|
868
|
+
) -> None:
|
|
869
|
+
await self._channel.send("press", self._timeout, locals_to_params(locals()))
|
|
870
|
+
|
|
871
|
+
async def check(
|
|
872
|
+
self,
|
|
873
|
+
selector: str,
|
|
874
|
+
position: Position = None,
|
|
875
|
+
timeout: float = None,
|
|
876
|
+
force: bool = None,
|
|
877
|
+
noWaitAfter: bool = None,
|
|
878
|
+
strict: bool = None,
|
|
879
|
+
trial: bool = None,
|
|
880
|
+
scroll: Literal["auto", "none"] = None,
|
|
881
|
+
) -> None:
|
|
882
|
+
await self._channel.send("check", self._timeout, locals_to_params(locals()))
|
|
883
|
+
|
|
884
|
+
async def uncheck(
|
|
885
|
+
self,
|
|
886
|
+
selector: str,
|
|
887
|
+
position: Position = None,
|
|
888
|
+
timeout: float = None,
|
|
889
|
+
force: bool = None,
|
|
890
|
+
noWaitAfter: bool = None,
|
|
891
|
+
strict: bool = None,
|
|
892
|
+
trial: bool = None,
|
|
893
|
+
scroll: Literal["auto", "none"] = None,
|
|
894
|
+
) -> None:
|
|
895
|
+
await self._channel.send("uncheck", self._timeout, locals_to_params(locals()))
|
|
896
|
+
|
|
897
|
+
async def wait_for_timeout(self, timeout: float) -> None:
|
|
898
|
+
await self._channel.send("waitForTimeout", None, {"waitTimeout": timeout})
|
|
899
|
+
|
|
900
|
+
async def wait_for_function(
|
|
901
|
+
self,
|
|
902
|
+
expression: str,
|
|
903
|
+
arg: Serializable = None,
|
|
904
|
+
timeout: float = None,
|
|
905
|
+
polling: Union[float, Literal["raf"]] = None,
|
|
906
|
+
) -> JSHandle:
|
|
907
|
+
if isinstance(polling, str) and polling != "raf":
|
|
908
|
+
raise Error(f"Unknown polling option: {polling}")
|
|
909
|
+
params = locals_to_params(locals())
|
|
910
|
+
params["arg"] = serialize_argument(arg)
|
|
911
|
+
if polling is not None and polling != "raf":
|
|
912
|
+
params["pollingInterval"] = polling
|
|
913
|
+
return from_channel(
|
|
914
|
+
await self._channel.send("waitForFunction", self._timeout, params)
|
|
915
|
+
)
|
|
916
|
+
|
|
917
|
+
async def title(self) -> str:
|
|
918
|
+
return await self._channel.send("title", None)
|
|
919
|
+
|
|
920
|
+
async def set_checked(
|
|
921
|
+
self,
|
|
922
|
+
selector: str,
|
|
923
|
+
checked: bool,
|
|
924
|
+
position: Position = None,
|
|
925
|
+
timeout: float = None,
|
|
926
|
+
force: bool = None,
|
|
927
|
+
noWaitAfter: bool = None,
|
|
928
|
+
strict: bool = None,
|
|
929
|
+
trial: bool = None,
|
|
930
|
+
scroll: Literal["auto", "none"] = None,
|
|
931
|
+
) -> None:
|
|
932
|
+
if checked:
|
|
933
|
+
await self.check(
|
|
934
|
+
selector=selector,
|
|
935
|
+
position=position,
|
|
936
|
+
timeout=timeout,
|
|
937
|
+
force=force,
|
|
938
|
+
strict=strict,
|
|
939
|
+
trial=trial,
|
|
940
|
+
scroll=scroll,
|
|
941
|
+
)
|
|
942
|
+
else:
|
|
943
|
+
await self.uncheck(
|
|
944
|
+
selector=selector,
|
|
945
|
+
position=position,
|
|
946
|
+
timeout=timeout,
|
|
947
|
+
force=force,
|
|
948
|
+
strict=strict,
|
|
949
|
+
trial=trial,
|
|
950
|
+
scroll=scroll,
|
|
951
|
+
)
|
|
952
|
+
|
|
953
|
+
async def _highlight(self, selector: str, style: str = None) -> None:
|
|
954
|
+
await self._channel.send(
|
|
955
|
+
"highlight", None, {"selector": selector, "style": style}
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
async def _hide_highlight(self, selector: str) -> None:
|
|
959
|
+
await self._channel.send("hideHighlight", None, {"selector": selector})
|