Capture, logging & automation¶
Screenshots, packet capture, the classic syslog relay, and UI automation.
(The richer OsTraceService log stream lives under Lockdown services.)
pymobiledevice3.services.screenshot.ScreenshotService ¶
Bases: LockdownService
Capture a screenshot of the device's screen via the com.apple.mobile.screenshotr service.
The service speaks the DeviceLink protocol and requires a developer image (developer mode) to be mounted on the device.
Source code in pymobiledevice3/services/screenshot.py
take_screenshot
async
¶
Capture the current screen contents.
Performs the DeviceLink handshake on first use, then requests a single screenshot.
Returns:
| Type | Description |
|---|---|
bytes
|
Raw image data as returned by the device (typically PNG or TIFF). |
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
If the service returns an unexpected response. |
Source code in pymobiledevice3/services/screenshot.py
pymobiledevice3.services.pcapd.PcapdService ¶
Bases: LockdownService
Capture network traffic from an iOS device.
Starting with iOS 5, Apple added a remote virtual interface (RVI) facility that mirrors the device's
network traffic. On macOS the virtual interface is enabled with the rvictl command; this service
exposes the same capability on other platforms. The service name used depends on the lockdown type
(legacy com.apple.pcapd for LockdownClient, RSD shim otherwise).
Source code in pymobiledevice3/services/pcapd.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
watch
async
¶
watch(packets_count: int = -1, process: Optional[str] = None, interface_name: Optional[str] = None) -> AsyncGenerator[Container, None]
Stream captured packets from the device as they arrive.
Each packet is parsed into its per-packet metadata fields (process pid/name, interface, timing,
protocol family, etc.) plus the raw frame data. For interfaces that lack a link-layer header
(and for pdp_ip cellular packets), a synthetic Ethernet header is prepended to data so
the output is valid for standard pcap consumers.
:yields: A parsed packet container; interface_type is an INTERFACE_NAMES value and
protocol_family a CrossPlatformAddressFamily value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
packets_count
|
int
|
Number of packets to yield before stopping; -1 streams indefinitely. |
-1
|
process
|
Optional[str]
|
If set, only yield packets whose pid (as a string) or process name matches. |
None
|
interface_name
|
Optional[str]
|
If set, only yield packets captured on this interface. |
None
|
Source code in pymobiledevice3/services/pcapd.py
write_to_pcap
async
¶
Write captured packets to a pcapng stream.
Consumes an async packet generator (such as watch) and writes each packet as an enhanced
packet block, annotating it with the originating process metadata. Uses the packet's own
timestamp if present, otherwise the current wall-clock time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out
|
A writable binary file-like object to receive the pcapng data. |
required | |
packet_generator
|
Async iterable yielding parsed packet containers. |
required |
Source code in pymobiledevice3/services/pcapd.py
pymobiledevice3.services.syslog.SyslogService ¶
Bases: LockdownService
Stream the device's live system log via the com.apple.syslog_relay service.
The service name used depends on the lockdown type (legacy com.apple.syslog_relay for
LockdownClient, RSD shim otherwise).
Source code in pymobiledevice3/services/syslog.py
watch
async
¶
Stream syslog lines from the device as they are emitted.
Reads the relay in chunks, splits on the syslog line delimiter, buffers any partial trailing line until the rest arrives, and decodes each complete line. Empty lines are skipped.
:yields: A single decoded syslog line (without the trailing delimiter).
Raises:
| Type | Description |
|---|---|
ConnectionTerminatedError
|
If the device closes the connection. |
Source code in pymobiledevice3/services/syslog.py
pymobiledevice3.services.debugserver_applist.DebugServerAppList ¶
Bases: LockdownService
Retrieve the list of installed applications as seen by debugserver, via the
com.apple.debugserver.DVTSecureSocketProxy.applist service.
Source code in pymobiledevice3/services/debugserver_applist.py
get
async
¶
Fetch the application list.
Reads the full plist response from the service and parses it.
Returns:
| Type | Description |
|---|---|
dict
|
The parsed application list, keyed by bundle identifier. |
Source code in pymobiledevice3/services/debugserver_applist.py
pymobiledevice3.services.accessibilityaudit.AccessibilityAudit ¶
Drive the device's accessibility audit daemon over DTX.
Provides access to accessibility capabilities and settings, on-device audits, the element inspector (focus traversal, simulated activation), and a stream of live accessibility events. Behavior differs across iOS versions (the iOS 15+ branch uses audit types, older versions use audit case IDs).
Use as an async context manager to establish the connection and flush the daemon's initial messages on entry and tear it down on exit::
async with AccessibilityAudit(lockdown) as audit:
issues = await audit.run_audit(await audit.supported_audits_types())
Source code in pymobiledevice3/services/accessibilityaudit.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
close
async
¶
Tear down the event queue and close the underlying DTX connection.
Source code in pymobiledevice3/services/accessibilityaudit.py
shell ¶
Open an interactive IPython shell with the connection ready.
The service is exposed as accessibility and the raw DTX channel as dtx; the
connection is closed when the shell exits.
Source code in pymobiledevice3/services/accessibilityaudit.py
capabilities
async
¶
Query the accessibility capabilities reported by the device.
Returns:
| Type | Description |
|---|---|
list[str]
|
The list of capability identifiers the device supports. |
Source code in pymobiledevice3/services/accessibilityaudit.py
run_audit
async
¶
Run accessibility audits on the device and wait for the results.
Begins the requested audits (by audit type on iOS 15+, by audit case ID on older versions) and blocks until the device reports completion, ignoring unrelated events in the meantime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
list
|
The audit types (iOS 15+) or audit case IDs to run. |
required |
Returns:
| Type | Description |
|---|---|
list[AXAuditIssue_v1]
|
The accessibility issues found by the audits. |
Source code in pymobiledevice3/services/accessibilityaudit.py
supported_audits_types
async
¶
Query the audit types (iOS 15+) or audit case IDs (older versions) the device supports.
Returns:
| Type | Description |
|---|---|
list
|
The supported audit identifiers, suitable for passing to |
Source code in pymobiledevice3/services/accessibilityaudit.py
settings
async
¶
Read the device's current accessibility settings.
Returns:
| Type | Description |
|---|---|
list[AXAuditDeviceSetting_v1]
|
The accessibility settings, each as a key/value pair. |
Source code in pymobiledevice3/services/accessibilityaudit.py
set_app_monitoring_enabled
async
¶
Enable or disable monitoring of the foreground app's accessibility elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
True to enable monitoring, False to disable. |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
set_monitored_event_type
async
¶
Set which inspector event type the device should report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
Optional[int]
|
The event type to monitor; None resets it to 0 (no specific type). |
None
|
Source code in pymobiledevice3/services/accessibilityaudit.py
set_show_ignored_elements
async
¶
Toggle whether the inspector includes accessibility-ignored elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
True to include ignored elements, False to hide them. |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
set_show_visuals
async
¶
Toggle the on-device visual overlay highlighting inspected elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
True to show the overlay, False to hide it. |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
iter_events
async
¶
iter_events(app_monitoring_enabled=True, monitored_event_type: Optional[int] = None) -> AsyncGenerator[Event, None]
Stream accessibility events from the device indefinitely.
Configures app monitoring and the monitored event type, then yields every event the device publishes.
:yields: Each accessibility Event with its deserialized payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_monitoring_enabled
|
Whether to enable foreground-app monitoring before streaming. |
True
|
|
monitored_event_type
|
Optional[int]
|
The event type to monitor; None means no specific type. |
None
|
Source code in pymobiledevice3/services/accessibilityaudit.py
move_focus_next
async
¶
perform_press
async
¶
Simulate a press/activation on an accessibility element.
Can only be used for processes that carry the task_for_pid-allow entitlement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
bytes
|
The platform element value identifying the target element. |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
move_focus
async
¶
Move the inspector focus in the given direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
Direction
|
The |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
set_setting
async
¶
Update a single accessibility setting on the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The setting identifier (matching |
required |
value
|
Any
|
The new value to assign to the setting. |
required |
Source code in pymobiledevice3/services/accessibilityaudit.py
reset_settings
async
¶
Reset all accessibility settings to their device defaults.
iter_elements
async
¶
Walk the focusable accessibility elements of the foreground app.
Enables app monitoring, then repeatedly advances the focus and yields each newly focused element. Stops once an already-seen element is revisited (loop detected). If the focus does not advance, it retries; persistent silence raises a timeout.
:yields: Each focused element as it is reached.
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If no focus events arrive after repeated retries. |
Source code in pymobiledevice3/services/accessibilityaudit.py
pymobiledevice3.services.webinspector.WebinspectorService ¶
Bases: LockdownService
Client for the com.apple.webinspector service (webinspectord).
Drives Safari/WebKit remote inspection and WebDriver automation: enumerates inspectable
applications and their pages, launches applications, and forwards the inspector/automation
socket traffic used to build InspectorSession and AutomationSession objects.
The service maintains a background receive task that dispatches incoming RPC notifications
and keeps the cached application/page state up to date. Call connect before issuing any
requests and close when done.
Source code in pymobiledevice3/services/webinspector.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
connect
async
¶
Establish the WebInspector session and start the background receive task.
Performs the initial handshake (reporting this client's identifier and processing the first reply) while watching for a disabled notification, then spawns the task that keeps consuming incoming messages. Safe to call repeatedly; subsequent calls are a no-op once the receive task is running.
Raises:
| Type | Description |
|---|---|
WebInspectorNotEnabledError
|
Web Inspector is disabled on the device. |
Source code in pymobiledevice3/services/webinspector.py
close
async
¶
Cancel the background receive task and close the underlying service connection.
Source code in pymobiledevice3/services/webinspector.py
automation_session
async
¶
Start a WebDriver automation session against an application.
Requests a new automation session, waits for the corresponding automation page to appear, sets up its forwarding socket, and waits until the page reports an automation connection id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Application
|
The application to automate. |
required |
Returns:
| Type | Description |
|---|---|
AutomationSession
|
A connected automation session. |
Raises:
| Type | Description |
|---|---|
RemoteAutomationNotEnabledError
|
Remote automation is not available on the device. |
Source code in pymobiledevice3/services/webinspector.py
inspector_session
async
¶
Open a Web Inspector session against a specific page of an application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Application
|
The application owning the page. |
required |
page
|
Page
|
The page to inspect. |
required |
Returns:
| Type | Description |
|---|---|
InspectorSession
|
A connected inspector session. For non-JavaScript pages the session waits for the inspection target before returning. |
Source code in pymobiledevice3/services/webinspector.py
get_open_pages
async
¶
Request and return the currently open pages of all connected applications.
Returns:
| Type | Description |
|---|---|
dict
|
A mapping of application name to the collection of its |
Source code in pymobiledevice3/services/webinspector.py
get_open_application_pages
async
¶
Enumerate all inspectable application/page pairs across connected applications.
Queries the connected applications and then waits for webinspectord to report their
listings before collecting the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Seconds to wait for the device to reply with the application listings. |
required |
Returns:
| Type | Description |
|---|---|
list[ApplicationPage]
|
A list of |
Source code in pymobiledevice3/services/webinspector.py
open_app
async
¶
Launch an application by bundle identifier and wait for it to connect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
str
|
The bundle identifier of the application to launch. |
required |
timeout
|
Union[float, int]
|
Seconds to wait for the application to appear as connected. |
3
|
Returns:
| Type | Description |
|---|---|
Application
|
The connected application. |
Raises:
| Type | Description |
|---|---|
LaunchingApplicationError
|
The application did not connect within the timeout. |
Source code in pymobiledevice3/services/webinspector.py
send_socket_data
async
¶
Forward an inspector/automation protocol message to a page's socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session identifier owning the socket. |
required |
app_id
|
str
|
The target application identifier. |
required |
page_id
|
int
|
The target page identifier. |
required |
data
|
dict
|
The protocol message to send; serialized to JSON before forwarding. |
required |
Source code in pymobiledevice3/services/webinspector.py
setup_inspector_socket
async
¶
Set up a forwarding socket for an inspector session without auto-pausing the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session identifier to associate with the socket. |
required |
app_id
|
str
|
The target application identifier. |
required |
page_id
|
int
|
The target page identifier. |
required |
Source code in pymobiledevice3/services/webinspector.py
find_page_id ¶
Look up the application and page for a known page identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_id
|
str
|
The page identifier to search for. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Application, Page]
|
A tuple of the owning application and the matching page. |
Raises:
| Type | Description |
|---|---|
KeyError
|
No page with the given identifier is currently known. |
Source code in pymobiledevice3/services/webinspector.py
flush_input
async
¶
Yield control for the given duration to let pending incoming messages be processed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
Union[float, int]
|
Seconds to sleep while the background receive task drains input. |
0
|
Source code in pymobiledevice3/services/webinspector.py
pymobiledevice3.services.wda.WdaServiceClient
dataclass
¶
Async WDA client that reaches the WDA server through a LockdownServiceProvider connection.
Instead of relying on a pre-existing local HTTP forwarder, this client opens a service
connection to the WDA port on the device for each request (via usbmux for an RSD-backed
provider, otherwise through the provider directly), writes a raw HTTP/1.1 request, and parses
the response. It exposes the same WebDriver actions as WdaClient as coroutines. The session
id returned by start_session is cached on session_id and used as the default for later calls.
Source code in pymobiledevice3/services/wda.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
start_session
async
¶
Start a WDA session, optionally launching a specific application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle_id
|
Optional[str]
|
Bundle identifier of the app to attach the session to; if omitted no specific app capability is requested. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The created session id, also cached on |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a session id. |
Source code in pymobiledevice3/services/wda.py
find_element
async
¶
Locate a single UI element and return its element id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
using
|
str
|
The locator strategy (e.g. |
required |
value
|
str
|
The locator value matched against |
required |
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The resolved element id. |
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available, or WDA did not return an element id. |
Source code in pymobiledevice3/services/wda.py
click
async
¶
Tap an element by its element id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_id
|
str
|
The element id to click. |
required |
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |
Source code in pymobiledevice3/services/wda.py
press_button
async
¶
Press a hardware/device button by name.
The name is normalized to a WDA button name. When a session is given the session-scoped
pressButton endpoint is tried first, falling back to the session keys endpoint; as a last
resort, home is delivered via the global home-screen endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Button name or alias (e.g. |
required |
session_id
|
Optional[str]
|
Session to use; if omitted only the global |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA supports neither the pressButton nor keys endpoints for this button. |
Source code in pymobiledevice3/services/wda.py
unlock
async
¶
Unlock the device, trying the session-scoped endpoint then the global one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA does not support the unlock endpoint. |
Source code in pymobiledevice3/services/wda.py
get_source
async
¶
Fetch the current UI hierarchy as an XML source tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; if omitted the global source endpoint is used. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The XML source string. |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a source string. |
Source code in pymobiledevice3/services/wda.py
get_screenshot
async
¶
Capture a screenshot and return the decoded PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; if omitted the global screenshot endpoint is used. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
The raw PNG image bytes (base64-decoded from the WDA response). |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a screenshot. |
Source code in pymobiledevice3/services/wda.py
get_status
async
¶
Return the WDA /status payload describing the server and device state.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The parsed status response. |
get_window_size
async
¶
Return the current window size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; required. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping with the window dimensions (e.g. |
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available, or WDA did not return a window size. |
Source code in pymobiledevice3/services/wda.py
send_keys
async
¶
Type text into the currently focused element.
Sends the text as individual characters, trying the wda/keys endpoint first and falling
back to the plain keys endpoint if the former is unavailable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to type. |
required |
session_id
|
Optional[str]
|
Session to use; required. |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |
Source code in pymobiledevice3/services/wda.py
swipe
async
¶
swipe(start_x: int, start_y: int, end_x: int, end_y: int, duration: float = 0.2, session_id: Optional[str] = None) -> None
Drag from a start coordinate to an end coordinate over a duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_x
|
int
|
Starting x coordinate. |
required |
start_y
|
int
|
Starting y coordinate. |
required |
end_x
|
int
|
Ending x coordinate. |
required |
end_y
|
int
|
Ending y coordinate. |
required |
duration
|
float
|
Gesture duration in seconds. |
0.2
|
session_id
|
Optional[str]
|
Session to use; required. |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |
Source code in pymobiledevice3/services/wda.py
pymobiledevice3.services.wda.WdaClient
dataclass
¶
Synchronous HTTP client for a running WebDriverAgent (WDA) server.
Talks to WDA over plain HTTP (default http://127.0.0.1:8100), expecting WDA to already be
reachable at base_url (e.g. via a local port forward). Provides session management and the
common WebDriver actions: element lookup, click, text input, button presses, swipes,
screenshots and source dumps. Once start_session is called the returned session id is cached
on session_id and used as the default for subsequent calls.
Source code in pymobiledevice3/services/wda.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
start_session ¶
Start a WDA session, optionally launching a specific application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle_id
|
Optional[str]
|
Bundle identifier of the app to attach the session to; if omitted no specific app capability is requested. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The created session id, also cached on |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a session id. |
Source code in pymobiledevice3/services/wda.py
find_element ¶
Locate a single UI element and return its element id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
using
|
str
|
The locator strategy (e.g. |
required |
value
|
str
|
The locator value matched against |
required |
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The resolved element id. |
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available, or WDA did not return an element id. |
Source code in pymobiledevice3/services/wda.py
click ¶
Tap an element by its element id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_id
|
str
|
The element id to click. |
required |
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |
Source code in pymobiledevice3/services/wda.py
press_button ¶
Press a hardware/device button by name.
The name is normalized to a WDA button name. When a session is given the session-scoped
pressButton endpoint is tried first, falling back to the session keys endpoint; as a last
resort, home is delivered via the global home-screen endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Button name or alias (e.g. |
required |
session_id
|
Optional[str]
|
Session to use; if omitted only the global |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA supports neither the pressButton nor keys endpoints for this button. |
Source code in pymobiledevice3/services/wda.py
unlock ¶
Unlock the device, trying the session-scoped endpoint then the global one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to use; defaults to the cached |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA does not support the unlock endpoint. |
Source code in pymobiledevice3/services/wda.py
get_source ¶
Fetch the current UI hierarchy as an XML source tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; if omitted the global source endpoint is used. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The XML source string. |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a source string. |
Source code in pymobiledevice3/services/wda.py
get_screenshot ¶
Capture a screenshot and return the decoded PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; if omitted the global screenshot endpoint is used. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
The raw PNG image bytes (base64-decoded from the WDA response). |
Raises:
| Type | Description |
|---|---|
WdaError
|
WDA did not return a screenshot. |
Source code in pymobiledevice3/services/wda.py
get_status ¶
Return the WDA /status payload describing the server and device state.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The parsed status response. |
get_window_size ¶
Return the current window size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
Optional[str]
|
Session to query; required. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping with the window dimensions (e.g. |
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available, or WDA did not return a window size. |
Source code in pymobiledevice3/services/wda.py
send_keys ¶
Type text into the currently focused element.
Sends the text as individual characters, trying the wda/keys endpoint first and falling
back to the plain keys endpoint if the former is unavailable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to type. |
required |
session_id
|
Optional[str]
|
Session to use; required. |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |
Source code in pymobiledevice3/services/wda.py
swipe ¶
swipe(start_x: int, start_y: int, end_x: int, end_y: int, duration: float = 0.2, session_id: Optional[str] = None) -> None
Drag from a start coordinate to an end coordinate over a duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_x
|
int
|
Starting x coordinate. |
required |
start_y
|
int
|
Starting y coordinate. |
required |
end_x
|
int
|
Ending x coordinate. |
required |
end_y
|
int
|
Ending y coordinate. |
required |
duration
|
float
|
Gesture duration in seconds. |
0.2
|
session_id
|
Optional[str]
|
Session to use; required. |
None
|
Raises:
| Type | Description |
|---|---|
WdaError
|
No session id is available. |