Overview
WebDriver provides:- W3C WebDriver protocol implementation
- Browser automation for testing
- Remote browser control
- Session management
- Multi-window/tab support
WebDriver allows you to control Ladybird programmatically for automated testing, scraping, and browser automation tasks.
Architecture
WebDriver runs as a TCP server that accepts connections from test frameworks and automation tools.Key components
Client
Handles WebDriver HTTP requests and maps them to browser actions:- Session management
- Navigation commands
- Element interaction
- Script execution
- Cookie management
- Screenshot capture
Services/WebDriver/Client.h:22
Session
Manages a browser automation session:- Unique session ID
- Multiple window management
- Timeouts configuration
- Page load strategy
- Capabilities negotiation
Services/WebDriver/Session.h:28
WebContentConnection
Bridges WebDriver to WebContent processes:Services/WebDriver/WebContentConnection.h
Starting WebDriver
Launch WebDriver with custom options:Configuration options
| Option | Default | Description |
|---|---|---|
--port | 8000 | TCP port to listen on |
--listen-address | 0.0.0.0 | IP address to bind to |
--headless | false | Run browser without GUI |
--certificate | - | Path to TLS certificate |
--force-cpu-painting | false | Disable GPU acceleration |
--expose-experimental-interfaces | false | Enable experimental web features |
--debug-process | - | Wait for debugger on specific process |
--default-time-zone | - | Set default timezone |
Creating a session
Clients create sessions by sending a POST request:W3C WebDriver endpoints
WebDriver implements the full W3C specification:Session commands
POST /session- Create new sessionDELETE /session/{id}- Delete sessionGET /status- Server status
Navigation
POST /session/{id}/url- Navigate to URLGET /session/{id}/url- Get current URLPOST /session/{id}/back- Navigate backPOST /session/{id}/forward- Navigate forwardPOST /session/{id}/refresh- Reload pageGET /session/{id}/title- Get page title
Window management
GET /session/{id}/window- Get window handleDELETE /session/{id}/window- Close windowPOST /session/{id}/window- Switch to windowGET /session/{id}/window/handles- List all windowsPOST /session/{id}/window/new- Open new windowGET /session/{id}/window/rect- Get window position/sizePOST /session/{id}/window/rect- Set window position/sizePOST /session/{id}/window/maximize- Maximize windowPOST /session/{id}/window/minimize- Minimize windowPOST /session/{id}/window/fullscreen- Enter fullscreen
Element interaction
POST /session/{id}/element- Find elementPOST /session/{id}/elements- Find elementsPOST /session/{id}/element/{id}/element- Find from elementPOST /session/{id}/element/{id}/click- Click elementPOST /session/{id}/element/{id}/clear- Clear elementPOST /session/{id}/element/{id}/value- Send keys to elementGET /session/{id}/element/{id}/text- Get element textGET /session/{id}/element/{id}/property/{name}- Get propertyGET /session/{id}/element/{id}/attribute/{name}- Get attributeGET /session/{id}/element/{id}/css/{name}- Get CSS value
Script execution
POST /session/{id}/execute/sync- Execute JavaScriptPOST /session/{id}/execute/async- Execute async JavaScript
Screenshots
GET /session/{id}/screenshot- Capture page screenshotGET /session/{id}/element/{id}/screenshot- Capture element screenshot
Cookies
GET /session/{id}/cookie- Get all cookiesGET /session/{id}/cookie/{name}- Get named cookiePOST /session/{id}/cookie- Add cookieDELETE /session/{id}/cookie/{name}- Delete cookieDELETE /session/{id}/cookie- Delete all cookies
Browser launching
WebDriver launches browser instances on-demand:- Client requests new session
- WebDriver creates IPC socket
- Browser process is spawned with socket path
- Browser connects back to WebDriver
- Session is established
Services/WebDriver/Client.h:20
Session management
Session flags
Sessions can have different modes:- Default: Standard browser session
- Headless: No graphical interface
- BidiMode: Bidirectional protocol support
Timeouts
Configure various timeout values:Page load strategy
- none: Return immediately
- eager: Return when DOMContentLoaded fires
- normal: Return when page fully loads (default)
Async actions
WebDriver handles asynchronous browser operations:Services/WebDriver/Session.h:67
Element location strategies
Supported locator strategies:- CSS selector:
.class #id element - Link text: Exact link text match
- Partial link text: Partial link text match
- Tag name: HTML tag name
- XPath: XPath expression
JavaScript execution
Execute arbitrary JavaScript in the page context:File uploads
WebDriver supports file input elements:Testing frameworks
WebDriver works with popular testing frameworks:Selenium (Python)
WebdriverIO (JavaScript)
Capabilities
WebDriver supports various capabilities:Error handling
WebDriver returns standard error codes:- invalid session id: Session not found
- no such element: Element doesn’t exist
- stale element reference: Element no longer in DOM
- element not interactable: Element cannot be interacted with
- javascript error: Script execution failed
- timeout: Operation exceeded timeout
Security considerations
- Bind to localhost for local testing
- Use firewall rules for network access
- Consider authentication for remote access
- Disable site isolation (required for WebDriver)
Performance tips
- Reuse sessions when possible
- Use headless mode for CI/CD
- Configure appropriate timeouts
- Minimize screenshot usage
- Batch element lookups
Related services
- WebContent: Controlled by WebDriver for automation
- Browser: Launched by WebDriver for each session
- RequestServer: Handles network requests during automation