Exceptions
Pydoll 抛出的异常,例如 ElementNotFound 和 WaitElementTimeout。详见 查找元素。
pydoll.exceptions
Pydoll Exception Classes
This module contains all exception classes used throughout the Pydoll library, organized into logical categories based on their function and usage patterns. Each category uses a base class to provide common functionality for related exceptions.
PydollException
ConnectionException
Bases: PydollException
Base class for exceptions related to browser connection.
ConnectionFailed
Bases: ConnectionException
Raised when connection to the browser cannot be established.
ReconnectionFailed
Bases: ConnectionException
Raised when an attempt to reconnect to the browser fails.
WebSocketConnectionClosed
Bases: ConnectionException
Raised when the WebSocket connection to the browser is closed unexpectedly.
NetworkError
Bases: ConnectionException
Raised when a general network error occurs during browser communication.
BrowserException
Bases: PydollException
Base class for exceptions related to browser process management.
BrowserNotRunning
Bases: BrowserException
Raised when attempting to interact with a browser that is not running.
FailedToStartBrowser
Bases: BrowserException
Raised when the browser process cannot be started.
UnsupportedOS
Bases: BrowserException
Raised when attempting to run on an unsupported operating system.
NoValidTabFound
Bases: BrowserException
Raised when no valid browser tab can be found or created.
InvalidConnectionPort
Bases: BrowserException
Raised when an invalid (non-positive) connection port is provided.
InvalidWebSocketAddress
Bases: BrowserException
Raised when an invalid WebSocket address is provided or required but missing.
MissingTargetOrWebSocket
Bases: BrowserException
Raised when a Tab has neither target ID nor WebSocket address available.
FingerprintContextConflict
Bases: BrowserException
Raised when a different fingerprint is applied within one browser context.
Service and shared workers are shared across all tabs of a browser context,
so a single context can only carry one fingerprint identity. Use a separate
browser context per identity (Browser.create_browser_context() +
Browser.new_tab(browser_context_id=...)).
message
class-attribute
instance-attribute
message = 'A different fingerprint is already applied to this browser context. Multiple fingerprints are only supported across separate browser contexts: create one context per identity via Browser.create_browser_context() and open each tab with new_tab(browser_context_id=...).'
ProtocolException
Bases: PydollException
Base class for exceptions related to CDP protocol communication.
TopLevelTargetRequired
Bases: ProtocolException
Raised when a command can only be executed on top-level targets.
InvalidCommand
Bases: ProtocolException
Raised when an invalid command is sent to the browser.
InvalidResponse
Bases: ProtocolException
Raised when an invalid response is received from the browser.
ResendCommandFailed
Bases: ProtocolException
Raised when an attempt to resend a failed command fails.
CommandExecutionTimeout
Bases: ProtocolException
Raised when a command execution times out.
CommandFailed
Bases: ProtocolException
Raised when the browser answers a command with a CDP error instead of a result.
Covers protocol-level rejections (unknown method, invalid params, session not found) and domain-level failures such as an object id that no longer resolves or an execution context destroyed by a navigation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
method |
CDP method that was rejected.
|
code |
JSON-RPC style error code reported by the browser.
|
data |
Optional extra detail the browser attached to the error.
|
InvalidCallback
Bases: ProtocolException
Raised when an invalid callback is provided for an event.
EventNotSupported
Bases: ProtocolException
Raised when an attempt is made to subscribe to an unsupported event.
ElementException
Bases: PydollException
Base class for exceptions related to element interactions.
ElementNotFound
Bases: ElementException
Raised when an element cannot be found in the DOM.
ElementNotVisible
Bases: ElementException
Raised when attempting to interact with an element that is not visible.
ElementNotInteractable
Bases: ElementException
Raised when attempting to interact with an element that cannot receive interaction.
ClickIntercepted
Bases: ElementException
Raised when a click operation is intercepted by another element.
ElementNotAFileInput
Bases: ElementException
Raised when attempting to use file input methods on a non-file input element.
ShadowRootNotFound
Bases: ElementException
Raised when an element does not have an attached shadow root.
TimeoutException
Bases: PydollException
Base class for exceptions related to timeouts.
PageLoadTimeout
Bases: TimeoutException
Raised when a page load operation times out.
WaitElementTimeout
Bases: TimeoutException
Raised when waiting for an element times out.
DownloadTimeout
Bases: TimeoutException
Raised when waiting for a file download to complete times out.
NavigationError
Bases: PydollException
Raised when page navigation fails (e.g., DNS resolution failure).
ConfigurationException
Bases: PydollException
Base class for exceptions related to configuration and options.
InvalidOptionsObject
Bases: ConfigurationException
Raised when an invalid options object is provided.
InvalidBrowserPath
Bases: ConfigurationException
Raised when an invalid browser executable path is provided.
ArgumentAlreadyExistsInOptions
Bases: ConfigurationException
Raised when attempting to add a duplicate argument to browser options.
ArgumentNotFoundInOptions
Bases: ConfigurationException
Raised when attempting to remove an argument that does not exist in browser options.
InvalidFileExtension
Bases: ConfigurationException
Raised when an unsupported file extension is provided.
InvalidTabInitialization
Bases: ConfigurationException
Raised when creating a Tab without connection_port, target_id or ws_address.
MissingScreenshotPath
Bases: ConfigurationException
Raised when take_screenshot is called without path and not returning base64.
DialogException
Bases: PydollException
Base class for exceptions related to browser dialogs.
NoDialogPresent
Bases: DialogException
Raised when attempting to interact with a dialog that doesn't exist.
NotAnIFrame
Bases: PydollException
Raised when an element is not an iframe.
InvalidIFrame
Bases: PydollException
Raised when an iframe is not valid.
IFrameNotFound
Bases: PydollException
Raised when an iframe is not found.
NetworkEventsNotEnabled
Bases: PydollException
Raised when network events are not enabled.
RequestException
Bases: PydollException
Base class for exceptions related to HTTP requests.
HTTPError
Bases: RequestException
Exception raised for HTTP error responses (4xx and 5xx status codes).
HarRecordingError
Bases: RequestException
Raised when HAR recording fails.
ScriptException
Bases: PydollException
Base class for exceptions related to JavaScript execution.
InvalidScriptWithElement
Bases: ScriptException
Raised when a script contains 'argument' but no element is provided.
WrongPrefsDict
Bases: PydollException
Raised when the prefs dict provided contains the 'prefs' key
ElementPreconditionError
Bases: ElementException
Raised when invalid or missing preconditions are provided for element operations.