You are looking at historical revision 42507 of this page. It may differ significantly from its current revision.
Webdriver API
This egg implements the WebDriver API as specified by the W3C.
Table of Contents
Dependencies
- srfi-34
- Exception handling
- srfi-35
- Exception types
- base64
- Decoding screenshot data
- http-client
- API interaction
- intarweb
- Supporting HTTP functionality
- uri-common
- Supporting HTTP functionality
- coops
- Object system
- alist-lib
- Handling alists from JSON objects
- medea
- JSON handling
Error Conditions
Every API error code (key "error" in the returned JSON data) gets its own condition type, prefixed by &. They all inherit from &wd-exception. E.g. the error code "invalid argument" becomes &invalid-argument.
Using WebDriver
The main "entry point" of the library is the <WebDriver> class. Using it directly is not possible, since you need a specialized subclass for a WebDriver server. This library ships with <Gecko>, as the name suggests this is an implementation for Geckodriver and thus Firefox; but it is easily possible to extend it for other drivers.
If you want to implement a new driver, you will want to subclass <WebDriver> and override launch, construct-capabilities, and maybe postprocess-results.
make-WebDriver
[procedure] (make-WebDriver browser #!optional options)Create a new instance of a WebDriver. browser must be the class of the driver you want to use (e.g. <Gecko>), and options will be handed to the driver.
terminate
[procedure] (terminate instance)Terminates the WebDriver instance.
Using the API
Communication
Data is sent to the API via a central class method. For convenience, there is a send-with-session variant that automatically adds the session id.
[procedure] (send instance data uri method)Sends data (an alist) to the endpoint uri using method. instance may be either a <WebDriver> or <WDElement> class/subclass.
[procedure] (send-with-session instance data uri method)Sends data (an alist) to the endpoint uri using method. instance may be either a <WebDriver> or <WDElement> class/subclass. Automatically adds the session id to the URL.
Session Management
[procedure] (initialize-session instance)Creates a new session for the given WebDriver instance. Will fail if a session already exists.
[procedure] (terminate-session instance)Terminates a session for the given WebDriver instance. This is also called automatically when using terminate.
API Access Methods
[procedure] (set-url instance url)[procedure] (url instance)
[procedure] (back instance)
[procedure] (forward instance)
[procedure] (refresh instance)
[procedure] (title instance)
[procedure] (status instance)
[procedure] (source instance)
[procedure] (screenshot instance)
[procedure] (print-page instance)
[procedure] (execute-async instance script args)
[procedure] (execute-sync instance script args)
These call the respective WebDriver API endpoints.
Timeouts
The following timeouts are defined:
- script: defaults to 30'000, specifies when to interrupt a script that is being evaluated. A nil value implies that scripts should never be interrupted, but instead run indefinitely.
- pageLoad: defaults to 300'000, provides the timeout limit used to interrupt an explicit navigation attempt.
- implicit: defaults to 0, specifies a time to wait for the element location strategy to complete when locating an element.