API Reference¶
This section uses mkdocstrings so signatures and docstrings are read from the current source code.
Common entry points:
| Object | Page |
|---|---|
Desktop |
Desktop |
Application |
Application |
Window |
Window |
Locator |
Locator |
Keyboard and Mouse |
Keyboard, Mouse |
Clipboard, FileDialog, MessageBox |
Clipboard, Dialogs |
ImageLocator and Screen |
ImageLocator / Screen |
JavaAccessBridge, ExcelApp, WordApp |
Java, Office |
| pytest plugin and CLI | pytest Plugin, CLI Reference |
Public Package API¶
The package exports these names through dolphin_desktop.__all__.
dolphin_desktop
¶
dolphin — Playwright-like testing library for Windows desktop applications.
AliasNotFoundError
¶
Bases: DolphinError
Raised when an alias is not found in the Object Repository.
Application
¶
Represents a running desktop application.
Do not instantiate directly — use :meth:Desktop.launch or
:meth:Desktop.connect.
Usage::
with desktop.launch("notepad.exe") as app:
win = app.window(title_re=".*Notepad")
win.get_by_role("Edit").type_text("hello")
Source code in src\dolphin_desktop\_application.py
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 | |
window
¶
window(
alias: str | None = None,
*,
title: str | None = None,
title_re: str | None = None,
class_name: str | None = None,
auto_id: str | None = None,
found_index: int = 0,
timeout: float = 10.0,
) -> Window
Return a :class:Window matching the given criteria or Object Repository alias.
Waits up to timeout seconds for the window to become visible.
Args:
alias: Optional Object Repository alias. When given, the alias is
resolved to pywinauto criteria and the returned :class:Window
stores the alias name so that :meth:Window.element can look up
child elements from the same YAML entry.
Source code in src\dolphin_desktop\_application.py
top_window
¶
windows
¶
close
¶
Ask the application to close gracefully.
Source code in src\dolphin_desktop\_application.py
kill
¶
is_webview2
¶
Return True if this application hosts an Edge WebView2 control.
Detection checks whether the process has loaded WebView2Loader.dll,
which is present in every app built with the Microsoft WebView2 SDK.
Returns False on any OS error, never raises.
Source code in src\dolphin_desktop\_application.py
is_electron
¶
Return True if this application is built on the Electron/Chromium runtime.
Detection is done in two passes:
- Window class — Electron/Chromium main windows have class
Chrome_WidgetWin_1. This is fast and works without elevated privileges. - Module signatures — if window enumeration finds nothing (e.g.
called before the first window appears), the process module list is
checked for
vk_swiftshader,libglesv2orelectronDLLs that ship with every Electron build.
Returns False on any error so callers never need to guard against
exceptions.
Source code in src\dolphin_desktop\_application.py
is_cef
¶
Return True if this application uses the Chromium Embedded Framework (CEF).
Detection checks for libcef.dll in the process module list while
excluding Electron-specific DLLs (vk_swiftshader, libglesv2,
electron). Because Electron is itself built on CEF, both would
carry libcef.dll — the absence of Electron modules distinguishes a
standalone CEF app (Spotify, Steam, Battle.net, etc.) from Electron.
Call this method after the app's main window has loaded — CEF DLLs are loaded lazily during UI initialization.
.. note::
UIA accessibility coverage for CEF apps varies widely. Apps that
expose --force-renderer-accessibility (or enable it internally)
provide a richer UIA tree. Spotify and Steam use bitmap rendering
for most UI, leaving only the window frame and a few controls in
the UIA tree. See docs/cef.md for workarounds.
Returns False on any OS error, never raises.
Source code in src\dolphin_desktop\_application.py
is_legacy_ie
¶
Return True if this application hosts an IE/Trident (MSHTML) browser.
Detection checks whether the process has loaded mshtml.dll, the
MSHTML rendering engine used by the WPF WebBrowser control and
older IE-based components. This DLL is present in every WPF app that
instantiates a WebBrowser control, regardless of the URL loaded.
.. note::
IE/Trident is End-of-Life since June 2022. The WPF WebBrowser
control still works in .NET 4.8 and partially in .NET 8 (Windows),
but Microsoft no longer ships security patches for MSHTML.
For new projects use Edge WebView2 (see docs/webview2.md).
Returns False on any OS error, never raises.
Source code in src\dolphin_desktop\_application.py
ApplicationError
¶
Bases: DolphinError
Raised when application launch or connection fails.
Backend
¶
Bases: ABC
Abstract base class for dolphin automation backends.
Subclasses must set :attr:id (unique string key) and :attr:platform
at class level, and implement all abstract methods.
Third-party packages register new backends via the
dolphin_desktop.backends entry-point group — each entry point must
point to a :class:Backend subclass.
Source code in src\dolphin_desktop\_backend.py
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 | |
find_element
abstractmethod
¶
Locate a single UI element matching criteria under parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Any
|
Root node to search under (type is backend-specific). |
required |
criteria
|
dict[str, Any]
|
Backend-specific search criteria (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
An opaque element handle understood by the other backend methods. |
Raises:
| Type | Description |
|---|---|
ElementNotFoundError
|
If no matching element is found within the configured timeout. |
Source code in src\dolphin_desktop\_backend.py
click
abstractmethod
¶
Perform a mouse click on element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
Element handle returned by :meth: |
required |
button
|
str
|
Mouse button: |
'left'
|
Source code in src\dolphin_desktop\_backend.py
type_text
abstractmethod
¶
Type text into element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
Element handle returned by :meth: |
required |
text
|
str
|
Text to type (sent as keyboard events). |
required |
Source code in src\dolphin_desktop\_backend.py
get_tree
abstractmethod
¶
Return the accessibility/element tree rooted at root as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Any
|
Root node to start from (type is backend-specific). |
required |
depth
|
int | None
|
Maximum depth to traverse; |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Nested dict with keys |
Source code in src\dolphin_desktop\_backend.py
screenshot
abstractmethod
¶
Capture a screenshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any | None
|
Element to capture, or |
None
|
Returns:
| Type | Description |
|---|---|
Image
|
Screenshot image. |
Source code in src\dolphin_desktop\_backend.py
is_available
¶
Return True if this backend can run on the current system.
The default implementation returns True; subclasses that depend on
optional packages or specific platforms should override this.
Source code in src\dolphin_desktop\_backend.py
description
¶
One-line human-readable description (shown by dolphin info backends).
Button
¶
Bases: Element
A clickable button control.
Usage::
window.button(name="OK").click()
assert window.button(name="Apply").is_enabled()
window.button(name="Cancel").wait_until_enabled()
Source code in src\dolphin_desktop\_element.py
CDPBackend
¶
Bases: Backend
Chrome DevTools Protocol backend - reserved, not yet implemented.
Source code in src\dolphin_desktop\_backend.py
CheckBox
¶
Bases: Element
A check box control.
Usage::
window.check_box(name="Remember me").check()
assert window.check_box(name="Remember me").is_checked()
window.check_box(name="Send updates").uncheck()
Source code in src\dolphin_desktop\_element.py
Clipboard
¶
Static helper for Windows clipboard operations.
Usage::
Clipboard.set_text("hello world")
text = Clipboard.get_text()
img = Clipboard.get_image() # PIL.Image or None
Clipboard.clear()
Source code in src\dolphin_desktop\_clipboard.py
get_text
staticmethod
¶
Read CF_UNICODETEXT from the clipboard; returns empty string if none.
Source code in src\dolphin_desktop\_clipboard.py
set_text
staticmethod
¶
Write text to the clipboard as CF_UNICODETEXT.
Source code in src\dolphin_desktop\_clipboard.py
get_image
staticmethod
¶
Read CF_DIB or CF_BITMAP from clipboard; returns None if not present.
Source code in src\dolphin_desktop\_clipboard.py
clear
staticmethod
¶
Empty the clipboard.
Source code in src\dolphin_desktop\_clipboard.py
ComboBox
¶
Bases: Element
A combo box (drop-down list) control.
Usage::
window.combo_box(name="Language").select_item("English")
window.combo_box().expand()
current = window.combo_box().selected_item()
Source code in src\dolphin_desktop\_element.py
Desktop
¶
Factory for :class:Application instances.
Usage::
desktop = Desktop()
app = desktop.launch("notepad.exe")
# or
app = desktop.connect(title_re=".*Notepad")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
|
'uia'
|
hidden
|
bool | None
|
|
None
|
Source code in src\dolphin_desktop\_desktop.py
16 17 18 19 20 21 22 23 24 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 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 | |
launch
¶
launch(
cmd: str,
*,
timeout: float = 10.0,
work_dir: str | None = None,
startup_delay: float = 0.5,
) -> Application
Start a new process and return an :class:Application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command line to execute (e.g. |
required |
timeout
|
float
|
Maximum seconds to wait for the process to start. |
10.0
|
work_dir
|
str | None
|
Optional working directory for the new process. |
None
|
startup_delay
|
float
|
Seconds to wait after the process starts before returning.
Useful for single-instance apps (e.g. Windows 11 Notepad) that
hand off to an existing process — a brief pause lets the target
window appear before :meth: |
0.5
|
Source code in src\dolphin_desktop\_desktop.py
connect
¶
connect(
*,
title: str | None = None,
title_re: str | None = None,
process: int | None = None,
path: str | None = None,
class_name: str | None = None,
found_index: int = 0,
timeout: float = 10.0,
) -> Application
Connect to an already-running process.
At least one search criterion must be provided.
When the criteria match more than one window (common for single-instance
apps such as Windows 11 Notepad, where several windows share a class
name or title pattern), found_index selects which match to use — the
first one (0) by default. Without this, pywinauto raises
ElementAmbiguousError on multiple matches.
Source code in src\dolphin_desktop\_desktop.py
for_legacy_apps
classmethod
¶
launch_qt
¶
Launch a Qt app with QT_ACCESSIBILITY=1.
launch_java
¶
Enable Java Access Bridge then launch a Java app.
Source code in src\dolphin_desktop\_desktop.py
launch_electron
¶
Launch an Electron/CEF app with accessibility enabled.
Source code in src\dolphin_desktop\_desktop.py
launch_cef
¶
Launch a standalone CEF (Chromium Embedded Framework) app.
Attempts to enable UIA accessibility by appending
--force-renderer-accessibility to the command line. This flag is
respected by CEF-based apps that pass unknown CLI arguments through to
the Chromium layer (e.g. some enterprise launchers, Battle.net Launcher).
.. warning::
Apps that wrap CEF in their own proprietary launcher (Spotify,
Steam) typically ignore this flag. For those apps, UIA
coverage is limited to what the app's own accessibility layer
exposes — see docs/cef.md for workarounds using
:class:~dolphin_desktop.ImageLocator.
Usage::
app = desktop.launch_cef(r"C:\path\to\cef_app.exe", timeout=20)
win = app.window(title_re=".*My CEF App.*", timeout=15)
assert app.is_cef()
Source code in src\dolphin_desktop\_desktop.py
launch_webview2
¶
Launch a WebView2-hosted WPF/WinForms app.
Edge WebView2 exposes a full UIA accessibility tree by default — no
special command-line flags are required. This method is a semantic
wrapper over :meth:launch that documents intent and mirrors the
launch_electron / launch_java / launch_qt family.
Source code in src\dolphin_desktop\_desktop.py
find_process
¶
find_process(
*,
name: str | None = None,
pid: int | None = None,
title: str | None = None,
title_re: str | None = None,
) -> Application | None
Return an Application connected to a matching running process, or None.
Source code in src\dolphin_desktop\_desktop.py
DolphinError
¶
Edit
¶
Bases: Element
A single-line or multi-line text input control.
Usage::
window.edit(name="Username").type_text("admin")
window.edit(name="Password").set_text("s3cr3t")
text = window.edit().text()
Source code in src\dolphin_desktop\_element.py
Element
¶
Bases: Locator
Base class for all specialized UI controls.
Extends :class:Locator with a named-control type. Use the factory
methods on :class:Window rather than instantiating directly:
Usage::
btn = window.button(name="OK")
btn.click()
edit = window.edit(name="File name")
edit.set_text("report.xlsx")
Source code in src\dolphin_desktop\_element.py
ElementNotFoundError
¶
Bases: DolphinError
Raised when an element cannot be found within the timeout.
ExcelApp
¶
COM wrapper for Microsoft Excel.
Source code in src\dolphin_desktop\_office.py
FileDialog
¶
Helper for interacting with Windows Open/Save file dialogs.
Source code in src\dolphin_desktop\_dialogs.py
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 | |
wait_for
staticmethod
¶
Wait for any open/save dialog to appear and return a FileDialog.
set_path
¶
Type a file path into the filename field and press Enter.
Source code in src\dolphin_desktop\_dialogs.py
confirm
¶
Click the Open / Save button.
Source code in src\dolphin_desktop\_dialogs.py
cancel
¶
Click the Cancel button.
Source code in src\dolphin_desktop\_dialogs.py
ImageBackend
¶
Bases: Backend
Image / template-matching backend - pixel-level fallback (requires [vision]).
Source code in src\dolphin_desktop\_backend.py
ImageLocator
¶
Locate a template image on screen using OpenCV template matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str | Path
|
Path to the template PNG/BMP/JPG image. |
required |
threshold
|
float
|
Minimum match confidence (0-1, default 0.85). |
0.85
|
scales
|
list[float] | None
|
List of scale factors to try during multi-scale matching
(e.g. |
None
|
region
|
tuple[int, int, int, int] | None
|
Default bounding box |
None
|
Source code in src\dolphin_desktop\_image.py
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 | |
find
¶
Return (cx, cy) of the best template match, or None.
Source code in src\dolphin_desktop\_image.py
find_with_size
¶
find_with_size(
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int, int, int] | None
Return (cx, cy, template_w, template_h) or None.
Used internally by the failover chain so that _ImageElement
has the correct bounding box.
Source code in src\dolphin_desktop\_image.py
find_all
¶
Return all match centres above threshold.
Source code in src\dolphin_desktop\_image.py
click
¶
Click the template match centre.
Source code in src\dolphin_desktop\_image.py
double_click
¶
Double-click the template match centre.
Source code in src\dolphin_desktop\_image.py
wait_for
¶
wait_for(
timeout: float = 10.0,
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int]
Poll every 0.5 s until the template appears; raise on timeout.
Source code in src\dolphin_desktop\_image.py
exists
¶
Return True if the template is found within timeout seconds.
Source code in src\dolphin_desktop\_image.py
as_element
¶
Find the template and return an _ImageElement proxy, or None.
Source code in src\dolphin_desktop\_image.py
JavaAccessBridge
¶
Utilities for enabling and checking the Java Access Bridge.
Source code in src\dolphin_desktop\_java.py
13 14 15 16 17 18 19 20 21 22 23 24 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 | |
is_enabled
staticmethod
¶
Return True if Java Access Bridge appears to be active.
Source code in src\dolphin_desktop\_java.py
enable
staticmethod
¶
Run jabswitch.exe /enable; raises RuntimeError on failure.
Source code in src\dolphin_desktop\_java.py
ensure_enabled
staticmethod
¶
java_home
staticmethod
¶
Return the JRE/JDK home directory, or None if not found.
Source code in src\dolphin_desktop\_java.py
Keyboard
¶
Send keystrokes to the currently focused window.
Key syntax follows pywinauto conventions::
Keyboard.press("^a") # Ctrl+A — select all
Keyboard.press("^s") # Ctrl+S — save
Keyboard.press("{ENTER}") # Enter key
Keyboard.press("+{F10}") # Shift+F10 — context menu
Keyboard.type("Hello World") # type plain text with spaces
Keyboard.hotkey("ctrl", "c") # Ctrl+C — copy
Special key tokens: {ENTER}, {TAB}, {ESC}, {BACK},
{DELETE}, {F1}…{F12}, {UP}, {DOWN}, {HOME}, {END}.
Modifiers: ^ ctrl, + shift, % alt.
Source code in src\dolphin_desktop\_keyboard.py
LinuxATSPIBackend
¶
Bases: Backend
Linux AT-SPI2 accessibility backend - reserved, not yet implemented.
Source code in src\dolphin_desktop\_backend.py
ListBox
¶
Bases: Element
A list box control.
Usage::
lb = window.list_box()
lb.select_item("Option A")
names = lb.items()
selected = lb.selected_items()
Source code in src\dolphin_desktop\_element.py
items
¶
selected_items
¶
Return the text of currently selected list items.
Source code in src\dolphin_desktop\_element.py
Locator
¶
Represents a way to find one or more UI elements.
Locators are lazy — they do not search for elements until an action or assertion method is called. This mirrors Playwright's Locator API.
Usage::
btn = window.get_by_title("OK", control_type="Button")
btn.click()
edit = window.get_by_role("Edit")
edit.type_text("hello")
assert edit.text() == "hello"
Source code in src\dolphin_desktop\_locator.py
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 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 | |
timeout
¶
Return a new Locator with a different timeout (does not mutate self).
Source code in src\dolphin_desktop\_locator.py
locator
¶
nth
¶
type_text
¶
Type text character by character (sends WM_CHAR events).
The default pause of 0.05 s between keystrokes matches pywinauto's own default and prevents missed/doubled keys in modern WinUI/XAML controls.
Source code in src\dolphin_desktop\_locator.py
set_text
¶
Replace the entire text content of an edit control.
Falls back to select-all + keyboard input for Document/RichEdit controls (e.g. Windows 11 Notepad) that do not support IValueProvider.SetValue.
Source code in src\dolphin_desktop\_locator.py
clear
¶
Clear the text of an edit control.
Source code in src\dolphin_desktop\_locator.py
press_key
¶
Send a key sequence to the element using pywinauto key syntax.
Source code in src\dolphin_desktop\_locator.py
select_item
¶
Select an item in a list/combo box by text or 0-based index.
Source code in src\dolphin_desktop\_locator.py
check
¶
Check a checkbox.
Source code in src\dolphin_desktop\_locator.py
uncheck
¶
Uncheck a checkbox.
Source code in src\dolphin_desktop\_locator.py
text
¶
Return the text content of the element.
For standard Edit controls this is window_text(). For Document/RichEdit controls (e.g. Windows 11 Notepad RichEditD2DPT) window_text() returns an empty string, so we fall back to select-all + clipboard.
Source code in src\dolphin_desktop\_locator.py
value
¶
Return the value of an edit/spinner control.
exists
¶
Return True if the element exists (and is visible) within timeout seconds.
bounding_box
¶
Return {left, top, right, bottom, width, height} in screen coords.
Source code in src\dolphin_desktop\_locator.py
wait_for
¶
Wait until the element reaches state ('visible', 'enabled', 'exists').
Source code in src\dolphin_desktop\_locator.py
wait_until_hidden
¶
Wait until the element is no longer visible.
Source code in src\dolphin_desktop\_locator.py
wait_until_enabled
¶
screenshot
¶
Capture the element as a PIL Image, optionally saving to path.
hover
¶
Move the mouse pointer over the element's centre.
Source code in src\dolphin_desktop\_locator.py
drag_to
¶
drag_to(
target: Locator | tuple[int, int],
*,
duration: float = 0.5,
button: str = "left",
) -> Locator
Drag from this element's centre to target.
Source code in src\dolphin_desktop\_locator.py
scroll
¶
Scroll at the element's centre. direction: 'up' or 'down'.
Source code in src\dolphin_desktop\_locator.py
get_attribute
¶
Return an attribute of the underlying element_info by name.
select_text
¶
all
¶
Return all matching elements as a list of Locators.
If depth is None, only direct children are returned. If depth is given (including 0), descendants up to that depth are returned.
Source code in src\dolphin_desktop\_locator.py
MacOSAccessibilityBackend
¶
Bases: Backend
macOS Accessibility API backend - reserved, not yet implemented.
Source code in src\dolphin_desktop\_backend.py
Menu
¶
Bases: Element
A menu bar item or top-level menu.
Usage::
window.menu("File").item("Save").click()
window.menu("Edit").item("Find...").click()
window.menu("View").item("Zoom").item("100%").click()
Source code in src\dolphin_desktop\_element.py
item
¶
Return a locator for a child menu item by its visible text.
The parent menu is automatically opened before the item is resolved. Supports chaining for nested submenus::
window.menu("View").item("Zoom").item("100%").click()
Source code in src\dolphin_desktop\_element.py
MenuItem
¶
Bases: Locator
A menu item that automatically opens its parent menu on resolution.
Created via :meth:Menu.item; not typically instantiated directly.
Clicking resolves the parent menu first (expanding it), then resolves the menu item itself. Works for both in-tree UIA menus and detached popup windows (e.g. Win32 context menus).
Supports chaining into nested submenus::
window.menu("View").item("Zoom").item("100%").click()
Source code in src\dolphin_desktop\_element.py
item
¶
MessageBox
¶
Helper for interacting with Windows MessageBox dialogs.
Source code in src\dolphin_desktop\_dialogs.py
wait_for
staticmethod
¶
Wait for a MessageBox (#32770) dialog and return a MessageBox.
text
¶
Return the message text from the Static control.
Source code in src\dolphin_desktop\_dialogs.py
click_ok
¶
click_cancel
¶
click_yes
¶
click_no
¶
click
¶
Click a button by its text label.
Accepts several candidate labels and clicks the first one present, so
the same call works regardless of the Windows display language
(e.g. "Yes" / "Tak").
Source code in src\dolphin_desktop\_dialogs.py
Mouse
¶
Control the mouse at absolute screen coordinates.
Usage::
Mouse.click(100, 200)
Mouse.right_click(500, 300)
Mouse.double_click(400, 150)
Mouse.move(x=640, y=480)
Mouse.scroll(x=400, y=300, wheel_dist=3)
Source code in src\dolphin_desktop\_mouse.py
scroll
staticmethod
¶
RadioButton
¶
Bases: Element
A radio button control.
Usage::
window.radio_button(name="Option A").select()
assert window.radio_button(name="Option A").is_checked()
Source code in src\dolphin_desktop\_element.py
RecordedAction
dataclass
¶
A single recorded user action.
Source code in src\dolphin_desktop\_recorder.py
Recorder
¶
Records mouse/keyboard interactions and generates dolphin Python test code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
str | None
|
Optional title fragment — only events in windows whose title contains
this string are recorded. If |
None
|
backend
|
str
|
pywinauto backend used in the generated code (default |
'uia'
|
stop_key
|
int
|
Virtual key code of the stop key (default |
123
|
Source code in src\dolphin_desktop\_recorder.py
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 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | |
start
¶
Install global low-level hooks and start recording.
Source code in src\dolphin_desktop\_recorder.py
stop
¶
Stop recording and unhook.
wait
¶
actions
¶
generate_code
¶
Generate Python test code from recorded actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str | Path | None
|
If given, the generated code is written to this path. |
None
|
func_name
|
str
|
Name of the generated test function. |
'test_recorded'
|
Returns:
| Type | Description |
|---|---|
str
|
The generated Python source (also written to output if provided). |
Source code in src\dolphin_desktop\_recorder.py
Screen
¶
Static helpers for full-screen capture, colour sampling, and OCR.
Source code in src\dolphin_desktop\_image.py
screenshot
staticmethod
¶
pixel_color
staticmethod
¶
Return the (R, G, B) colour at screen coordinate (x, y).
find_image
staticmethod
¶
find_image(
template: str | Path,
threshold: float = 0.85,
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int] | None
Convenience wrapper: create an ImageLocator and call find().
Source code in src\dolphin_desktop\_image.py
text
staticmethod
¶
Return OCR text of the screen or region via pytesseract.
find_text
staticmethod
¶
Return the centre (x, y) of the first bounding box containing text, or None.
Source code in src\dolphin_desktop\_image.py
Tab
¶
Bases: Element
A tab control (notebook / property sheet).
Usage::
window.tab().select_tab("General")
window.tab(name="Options").select_tab("Advanced")
Source code in src\dolphin_desktop\_element.py
select_tab
¶
Select a tab page by its visible name.
Source code in src\dolphin_desktop\_element.py
Toolbar
¶
Bases: Element
A toolbar control.
Usage::
window.toolbar().button("Bold").click()
window.toolbar(name="Formatting").button("Italic").click()
Source code in src\dolphin_desktop\_element.py
button
¶
Return a :class:Button locator for a toolbar button by its accessible name.
TraceSession
¶
Records one test run to a local directory (trace.db + screenshots/).
Source code in src\dolphin_desktop\_trace.py
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 | |
record_step
¶
record_step(
action: str,
selector: str | None,
element: Any = None,
error: str | None = None,
) -> None
Record one action step. In on-failure mode screenshots are only taken when the step produced an error; in always mode every step gets a screenshot.
Source code in src\dolphin_desktop\_trace.py
finish
¶
finish(
status: str,
error_message: str | None = None,
error_traceback: str | None = None,
) -> None
Finalise the run record. Discards the run dir on pass in on-failure mode.
Source code in src\dolphin_desktop\_trace.py
close_without_finish
¶
Close the DB connection without writing a final status (e.g. on error).
Tree
¶
Bases: Element
A tree view control.
Usage::
tree = window.tree()
tree.expand_item("Root", "Branch")
tree.select_item_by_path("Root", "Branch", "Leaf")
Source code in src\dolphin_desktop\_element.py
expand_item
¶
Expand a tree node by its path of node titles.
Source code in src\dolphin_desktop\_element.py
select_item_by_path
¶
Select a tree node by path, expanding parent nodes as needed.
Source code in src\dolphin_desktop\_element.py
UIABackend
¶
Bases: Backend
Microsoft UI Automation - default backend for modern Windows apps.
Source code in src\dolphin_desktop\_backend.py
VideoRecorder
¶
Records the screen to MP4 via a background ffmpeg process.
Typical lifecycle::
rec = VideoRecorder(fps=10)
rec.start()
# ... test runs ...
rec.stop()
if failed:
rec.encode(Path("output.mp4"))
rec.discard()
Source code in src\dolphin_desktop\_video.py
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 | |
start
¶
Start an ffmpeg gdigrab process recording the desktop to MP4.
Raises RuntimeError if ffmpeg cannot be found.
Silently skips if already started.
Source code in src\dolphin_desktop\_video.py
stop
¶
Stop the ffmpeg process, letting it finalise the MP4 container.
Sends q on ffmpeg's stdin so the moov atom is written and the file
stays playable; falls back to terminate/kill if it does not exit.
Source code in src\dolphin_desktop\_video.py
encode
¶
Save the recorded MP4 to output_path.
ffmpeg already produced an encoded MP4 during capture, so this simply
copies it to the destination. Returns output_path on success.
Raises RuntimeError if nothing was recorded.
Source code in src\dolphin_desktop\_video.py
discard
¶
Delete the temporary recording directory.
WaitTimeoutError
¶
Bases: DolphinError
Raised when a wait condition is not met within the allowed time.
Win32Backend
¶
Bases: Backend
Win32 HWND backend - best for legacy apps (MFC, VB6, Delphi/VCL).
Source code in src\dolphin_desktop\_backend.py
Window
¶
Represents a single window (top-level or dialog).
Obtain via :meth:Application.window or :meth:Application.top_window.
Usage::
window = app.window(title_re=".*Notepad")
window.get_by_role("Edit").type_text("hello")
window.screenshot("snap.png")
Source code in src\dolphin_desktop\_window.py
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 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 | |
locator
¶
Find elements by arbitrary pywinauto criteria (title, control_type, auto_id, …).
Source code in src\dolphin_desktop\_window.py
get_by_title
¶
Find an element by its accessible name / window text.
Source code in src\dolphin_desktop\_window.py
get_by_role
¶
Find an element by its UIA control type (e.g. 'Button', 'Edit', 'List').
Source code in src\dolphin_desktop\_window.py
get_by_automation_id
¶
get_by_class
¶
get_by_text
¶
Alias for get_by_title — find by exact visible text.
Source code in src\dolphin_desktop\_window.py
button
¶
Find a Button control.
Usage::
window.button(name="OK").click()
window.button(name="Apply").is_enabled()
Source code in src\dolphin_desktop\_window.py
edit
¶
Find an Edit (text input) control.
Usage::
window.edit(name="Username").type_text("admin")
window.edit().set_text("hello")
Source code in src\dolphin_desktop\_window.py
combo_box
¶
Find a ComboBox (drop-down) control.
Usage::
window.combo_box(name="Language").select_item("English")
Source code in src\dolphin_desktop\_window.py
check_box
¶
Find a CheckBox control.
Usage::
window.check_box(name="Remember me").check()
Source code in src\dolphin_desktop\_window.py
radio_button
¶
Find a RadioButton control.
Usage::
window.radio_button(name="Option A").select()
Source code in src\dolphin_desktop\_window.py
menu
¶
Find a top-level menu item (e.g. File, Edit, View).
Usage::
window.menu("File").item("Save").click()
window.menu("Edit").item("Find...").click()
Source code in src\dolphin_desktop\_window.py
tree
¶
Find a Tree (tree view) control.
Usage::
window.tree().expand_item("Root", "Branch")
window.tree().select_item_by_path("Root", "Node")
Source code in src\dolphin_desktop\_window.py
list_box
¶
Find a ListBox control.
Usage::
window.list_box().select_item("Option A")
names = window.list_box().items()
Source code in src\dolphin_desktop\_window.py
tab
¶
Find a Tab (notebook) control.
Usage::
window.tab().select_tab("General")
Source code in src\dolphin_desktop\_window.py
toolbar
¶
Find a Toolbar control.
Usage::
window.toolbar().button("Bold").click()
Source code in src\dolphin_desktop\_window.py
element
¶
Find an element by alias from the Object Repository.
Looks up alias in the children of the current window's alias first
(if this window was created via app.window("alias")), then falls
back to a flat top-level search.
Usage::
objects.load("objects/login.yaml")
win = app.window("login_window")
win.element("email_input").type_text("user@example.com")
Source code in src\dolphin_desktop\_window.py
image
¶
image(
template: str | Path,
*,
confidence: float = 0.85,
scales: list[float] | None = None,
) -> Any
Find an element by template image matching, scoped to this window's bounds.
Uses OpenCV template matching (requires dolphin-desktop[vision]).
Usage::
window.image("btn_ok.png").click()
window.image("icon.png", confidence=0.9).wait_for(timeout=5)
window.image("logo.png", scales=[0.8, 1.0, 1.2]).exists()
Source code in src\dolphin_desktop\_window.py
find_by_xpath
¶
Find an element using a simplified XPath expression.
Supports a subset of XPath syntax for navigating the UIA element tree:
Usage::
window.find_by_xpath("//Button[@Name='OK']").click()
window.find_by_xpath("//Edit[@AutomationId='tbSearch']").type_text("q")
window.find_by_xpath("//MenuBar//MenuItem[@Name='File']")
Supported syntax:
//Tagor/Tag— find descendant with that control type[@Name='val']→title='val'[@AutomationId='val']→auto_id='val'[@ClassName='val']→class_name='val'
Multiple segments chain locators::
//MenuBar//MenuItem[@Name='File']
Source code in src\dolphin_desktop\_window.py
screenshot
¶
Capture the window as a PIL Image, optionally saving to path.
wait_for_close
¶
Wait until the window is no longer visible.
Source code in src\dolphin_desktop\_window.py
wait_until_ready
¶
Wait until the window is ready (not busy).
Source code in src\dolphin_desktop\_window.py
WindowNotFoundError
¶
Bases: DolphinError
Raised when a window cannot be found.
WordApp
¶
COM wrapper for Microsoft Word.
Source code in src\dolphin_desktop\_office.py
config
¶
config(
*,
timeout: float | None = None,
poll_interval: float | None = None,
trace_mode: str | None = None,
video_mode: str | None = None,
video_fps: int | None = None,
log_level: str | None = None,
retry_count: int | None = None,
) -> None
Set global dolphin defaults.
Args:
timeout: Default element-wait timeout in seconds (default 10.0).
Also settable via the DOLPHIN_TIMEOUT environment variable or
the --dolphin-timeout pytest CLI option.
poll_interval: Polling interval for retry loops, in seconds (default 0.1).
trace_mode: Trace capture mode — "off", "on-failure" (default),
or "always". Also settable via DOLPHIN_TRACE env var or
the --dolphin-trace pytest CLI option.
video_mode: Video recording mode — "off", "keepfailedonly" (default),
or "keepall". Also settable via DOLPHIN_VIDEO env var or
the --dolphin-video pytest CLI option.
video_fps: Capture frame rate in frames/second (default 10, max 30).
Also settable via DOLPHIN_VIDEO_FPS env var.
log_level: Logging verbosity — "DEBUG", "INFO" (default), or
"ERROR". Also settable via DOLPHIN_LOG_LEVEL env var or
the --dolphin-log-level pytest CLI option.
retry_count: Number of times to retry a test that fails with a transient
dolphin error (ElementNotFoundError / WaitTimeoutError).
Default 0 (no retry). Also settable via DOLPHIN_RETRY env var
or the --dolphin-retry pytest CLI option.
Source code in src\dolphin_desktop\_config.py
get_logger
¶
Return logging.getLogger("dolphin") or a named child logger.
list_backends
¶
Return info dicts for all registered backends.
Each dict has keys: id, platform, class, available,
description, source ("built-in" or entry-point value).
Plugin backends from dolphin_desktop.backends entry points are
included automatically.
Source code in src\dolphin_desktop\_backend.py
register_backend
¶
Register a :class:Backend subclass in the global registry.
This is the programmatic alternative to the dolphin_desktop.backends
entry-point mechanism — useful for in-process backend registration in tests
or extension packages that don't install an entry point.
Returns cls unchanged so it can be used as a decorator::
@dolphin_desktop._backend.register
class MyBackend(Backend):
id = "my_backend"
...
Source code in src\dolphin_desktop\_backend.py
resolve_backend
¶
Return an instantiated :class:Backend for backend_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_id
|
str
|
One of the registered backend IDs ( |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If backend_id is not found in the registry. |
Source code in src\dolphin_desktop\_backend.py
selfheal_stats
¶
Return the last n fallback events from the telemetry log.
Args:
n: Maximum number of recent records to return.
file: Path to the JSONL telemetry file. Defaults to the value of
DOLPHIN_SELFHEAL_FILE env var or .dolphin-selfheal.jsonl.
Returns:
List of event dicts with keys ts, test, primary, fallback.
Source code in src\dolphin_desktop\_selfheal.py
setup_logging
¶
Configure the dolphin root logger. Idempotent — safe to call repeatedly.
Source code in src\dolphin_desktop\_logging.py
telemetry_capture_exception
¶
Send a dolphin-internal exception to Sentry. No-op when telemetry is disabled.
Source code in src\dolphin_desktop\_telemetry.py
telemetry_enabled
¶
telemetry_init
¶
Initialize Sentry telemetry. Idempotent; silent if disabled or not installed.
Source code in src\dolphin_desktop\_telemetry.py
trace_generate_html
¶
Read trace.db in run_dir, write trace.html, and return its path.
Source code in src\dolphin_desktop\_trace.py
write_crash_dump
¶
write_crash_dump(
exc: BaseException | None = None,
output_dir: Path | None = None,
extra: dict[str, Any] | None = None,
) -> Path
Write crash-<timestamp>.zip with full diagnostics.
Args:
exc: The exception that triggered the dump (None → captures current stack).
output_dir: Where to write the ZIP (default: dolphin-crashes/).
extra: Additional key/value pairs written verbatim to extra.txt.
Returns: Absolute path of the written ZIP file.