wd
is a simple tool for interacting with servers that implement the
W3C WebDriver API.
It can be used for web automation tasks such as testing and scraping.
You can use Selenium as the WebDriver server to control browsers on your own machine.
There are commercial services that offer the WebDriver API remotely; see "Functional Test Services" here.
See the WebDriver spec for details about the protocol and behavior.
bash
-
perl
(5.14 or greater) curl
$ export WEBDRIVER_BROWSER=chrome
$ export WEBDRIVER_SESSION="$(wd new-session)"
$ wd go https://github.com/mbrock/wd
$ wd screenshot > /tmp/wd.png
$ wd click "$(wd find css .user-mention)"
$ wd exec 'return document.title'
-
WEBDRIVER_URL
: WebDriver API URL (defaulthttp://127.0.0.1:4444/wd/hub
)
Prints the new session ID.
All other commands expect this ID to be in WEBDRIVER_SESSION
, so
export WEBDRIVER_SESSION="$(wd new-session)"
is a useful pattern.
You must configure desired capabilities by setting either
-
WEBDRIVER_CAPABILITIES
to a stringified JSON object, or -
WEBDRIVER_BROWSER
to a browser name (chrome
,firefox
, etc).
Deletes the current session.
Opens <url>
in the current window.
Navigates back in the current window.
Navigates forward in the current window.
Refreshes the page of the current window.
Finds one matching element and prints its element ID.
The <strategy>
can be one of:
-
css
(CSS selector) -
xpath
(XPath selector) -
id
(element ID) -
name
(element name) -
class
(element class name) -
tag
(element tag name) -
link
(element link text) -
partial
(partial element link text)
The <selector>
values are concatenated for convenience.
Example:
$ wd find css article header img.avatar
See wd find
; finds all matching elements.
See wd find
; finds one matching sub-element.
See wd find
; finds all matching sub-elements.
Exits with a non-zero status if the element is not a selected or
checked input
or option
.
Exits with a non-zero status if the element is not an enabled form control.
Prints an element attribute value.
Exits with non-zero status if the given attribute does not exist.
Prints an element CSS property value.
Exits with non-zero status if the given style property does not exist.
Prints an element's innerText
.
Prints the tag name of an element.
Clicks an element.
Clears the value, checkedness, or text content of an element.
Sends keys to an element.
Key arguments are concatenated for convenience.
Example:
$ wd send-keys "$(wd find id search)" webdriver json api
Evaluates the JavaScript code <body>
as a function called with the
given arguments.
Prints the return value of the specified function.
Evaluates as in wd execute
but waiting for the script to invoke a callback
which is passed as an additional final argument to the specified function.
Prints the value finally passed to the callback.
Prints the URL of the page in the current window.
Prints the title of the page in the current window.
Prints the raw HTML source of the page in the current window.
Prints the current window's width and height on separate lines.
Changes the size of the current window.
Maximizes the current window.
Prints the window handle of the current window.
Prints a list of all window handles in the current session.
Close the current window.
Changes which window is the current window.
Changes the current frame.
<frame-id>
can be either a number or an element ID.
See the specification for exact details.
Resets the current frame to the top level.
Sets the current frame to the parent of the current frame.
See the spec for details on cookie JSON serialization.
Prints the currently set cookies as a JSON array.
Prints the cookie named <name>
as JSON.
Adds a cookie according to the given keys/values.
Example: wd add-cookie name '"user"' value '"mbrock"'
Deletes the cookie whose name is <name>
.
Deletes all cookies.
Prints a binary PNG screenshot to stdout.
Prints a binary PNG screenshot of a specific element to stdout.
(Not supported by Chrome.)