Overview
nodriver defines custom exception classes to handle errors from the Chrome DevTools Protocol and browser operations. Understanding these exceptions helps you write robust automation scripts.Exception Classes
ProtocolException
Raised when a Chrome DevTools Protocol command fails or returns an error.str
Human-readable error message.
int | None
Error code from the protocol, if available.
tuple
Original exception arguments.
- Invalid node IDs in DOM operations
- Calling CDP methods before enabling the domain
- Invalid CSS selectors
- Network errors
- JavaScript execution errors
SettingClassVarNotAllowedException
Raised when attempting to set class variables that should not be modified.Standard Python Exceptions
nodriver also raises standard Python exceptions in certain situations:FileNotFoundError
Raised when:- Chrome/Chromium executable cannot be found
- Specified browser executable path doesn’t exist
- Extension files cannot be found
RuntimeError
Raised when:- Creating Browser/Tab objects outside an async context
- Invalid browser state operations
ValueError
Raised when:- Invalid configuration arguments
- Invalid parameter values
TimeoutError
Raised when:- Element finding operations timeout
- Wait conditions not met within timeout period
Error Handling Patterns
Graceful degradation
Retry logic
Context manager for cleanup
Logging errors
Type-specific handling
Best Practices
Always handle ProtocolException when sending CDP commands, as they can fail for many reasons.
Use timeouts appropriately - Set reasonable timeouts for find/select operations based on your use case.
Log errors with context - Include relevant information like URLs, selectors, and operation details in error logs.
Common Error Messages
See also
- Tab class - Methods that may raise exceptions
- CDP Usage - Working with CDP commands
- ProtocolException source - Exception implementation