The API below was written regarding to the source code of different Webdriver implementations. All of them partially differ from the official W3C specification.
The standard: https://www.w3.org/TR/webdriver/
Chrome: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/
Firefox (Geckodriver): https://github.com/mozilla/geckodriver https://github.com/mozilla/webdriver-rust/
Phantom.js (Ghostdriver) https://github.com/detro/ghostdriver/blob/
The API below was written regarding to the source code of different Webdriver implementations. All of them partially differ from the official W3C specification. The standard: https://www.w3.org/TR/webdriver/ Chrome: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/ Firefox (Geckodriver): https://github.com/mozilla/geckodriver https://github.com/mozilla/webdriver-rust/ Phantom.js (Ghostdriver) https://github.com/detro/ghostdriver/blob/
Simulates submitting an alert dialog (pressing OK button).
Simulates submitting an alert dialog (pressing OK button).
(back driver)
Move backwards in a browser's history.
Move backwards in a browser's history.
(boot-driver type)
(boot-driver type opt)
Three-in-one: creates a driver, starts a process and creates a new session. Returns the driver instance.
Arguments:
type
a keyword determines a driver type.
opt
a map of all possible parameters that create-driver
,
run-driver
and connect-driver
may accept.
Three-in-one: creates a driver, starts a process and creates a new session. Returns the driver instance. Arguments: - `type` a keyword determines a driver type. - `opt` a map of all possible parameters that `create-driver`, `run-driver` and `connect-driver` may accept.
(child driver ancestor-el q)
Finds a single element under given root element.
Finds a single element under given root element.
(children driver ancestor-el q)
Finds multiple elements under given root element.
Finds multiple elements under given root element.
Launches Chrome driver. A shortcut for boot-driver
.
Launches Chrome driver. A shortcut for `boot-driver`.
(chrome-headless)
(chrome-headless opt)
Launches headless Chrome driver. A shortcut for boot-driver
.
Launches headless Chrome driver. A shortcut for `boot-driver`.
(chrome? driver)
Returns true if a driver is a Chrome instance.
Returns true if a driver is a Chrome instance.
(clear driver q & more)
Clears an element (input, textarea) found with a query.
0.1.6: multiple queries added.
Clears an element (input, textarea) found with a query. 0.1.6: multiple queries added.
(clear-el driver el)
Clears an element by its identifier.
Clears an element by its identifier.
(click driver q)
Clicks on an element (a link, a button, etc).
Clicks on an element (a link, a button, etc).
(click-el driver el)
Click on an element having its system id.
Click on an element having its system id.
(click-single driver q)
Click on an element checking that there is only one element found. Throw an exception otherwise.
Click on an element checking that there is only one element found. Throw an exception otherwise.
(click-visible driver q & [opt])
Waits until an element becomes visible, then clicks on it.
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element becomes visible, then clicks on it. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
Closes the current browser window.
Closes the current browser window.
(connect-driver driver & [opt])
Connects to a running Webdriver server.
Creates a new session on Webdriver HTTP server. Sets the session to the driver. Returns the modified driver.
Arguments:
opt
: an map of the following optional parameters:-- :capabilities
a map of desired capabilities your
browser should support;
-- :desired-capabilities
: an alias for :capabilities
.
Connects to a running Webdriver server. Creates a new session on Webdriver HTTP server. Sets the session to the driver. Returns the modified driver. Arguments: - `opt`: an map of the following optional parameters: -- `:capabilities` a map of desired capabilities your browser should support; -- `:desired-capabilities`: an alias for `:capabilities`. See https://www.w3.org/TR/webdriver/#capabilities
(connectable? host port)
Checks whether it's possible to connect a given host/port pair.
Checks whether it's possible to connect a given host/port pair.
(create-driver type & [opt])
Creates a new driver instance.
Returns an atom that represents driver's state. Some functions, for example creating or deleting a session may change its state.
The function does not start a process or open a window. It just creates an atom without side effects.
Arguments:
type
is a keyword determines what driver to use. The supported
browsers are :firefox
, :chrome
, :phantom
and :safari
.
opt
is a map with additional options for a driver. The supported
options are:
-- :host
is a string with either IP or hostname. Use it if the
server is run not locally but somethere in your network.
-- :port
is an integer value what HTTP port to use. It is taken
from the defaults
global map if is not passed. If there is no
port in that map, a random-generated port is used.
-- :locator
is a string determs what algorithm to use by default
when finding elements on a page. default-locator
variable is used
if not passed.
Creates a new driver instance. Returns an atom that represents driver's state. Some functions, for example creating or deleting a session may change its state. The function does not start a process or open a window. It just creates an atom without side effects. Arguments: - `type` is a keyword determines what driver to use. The supported browsers are `:firefox`, `:chrome`, `:phantom` and `:safari`. - `opt` is a map with additional options for a driver. The supported options are: -- `:host` is a string with either IP or hostname. Use it if the server is run not locally but somethere in your network. -- `:port` is an integer value what HTTP port to use. It is taken from the `defaults` global map if is not passed. If there is no port in that map, a random-generated port is used. -- `:locator` is a string determs what algorithm to use by default when finding elements on a page. `default-locator` variable is used if not passed.
(create-session driver & [capabilities])
Initiates a new session for a driver. Opens a browser window as a side-effect. All the further requests are made within specific session. Some drivers may work with only one active session. Returns a long string identifier.
Initiates a new session for a driver. Opens a browser window as a side-effect. All the further requests are made within specific session. Some drivers may work with only one active session. Returns a long string identifier.
(delete-cookie driver cookie-name)
Deletes a cookie by its name.
Deletes a cookie by its name.
(delete-cookies driver)
Deletes all the cookies for all domains.
Deletes all the cookies for all domains.
(delete-session driver)
Deletes a session. Closes a browser window.
Deletes a session. Closes a browser window.
(disconnect-driver driver)
Disconnects from a running Webdriver server.
Closes the current session that is stored in the driver if it still exists. Removes the session from the driver instance. Returns modified driver.
Disconnects from a running Webdriver server. Closes the current session that is stored in the driver if it still exists. Removes the session from the driver instance. Returns modified driver.
(discover-port type host)
Finds a port for a driver type.
Takes a default one from defaults
map. If it's already taken,
continues to take random ports until if finds non-busy one.
Arguments:
type
: a keyword, browser type (:chrome, :firefox, etc),
host
: a string, hostname or IP.
Returns a port as an integer.
Finds a port for a driver type. Takes a default one from `defaults` map. If it's already taken, continues to take random ports until if finds non-busy one. Arguments: - `type`: a keyword, browser type (:chrome, :firefox, etc), - `host`: a string, hostname or IP. Returns a port as an integer.
Simulates cancelling an alert dialog (pressing cross button).
Simulates cancelling an alert dialog (pressing cross button).
(dispatch-driver driver & _)
Returns the current driver's type. Used as dispatcher in multimethods.
Returns the current driver's type. Used as dispatcher in multimethods.
Checks whether an element is displayed by its identifier.
Note: Safari does not have native displayed
implementation, we
have to check some common cases manually (CSS display, visibility,
etc).
Returns true or false.
Checks whether an element is displayed by its identifier. Note: Safari does not have native `displayed` implementation, we have to check some common cases manually (CSS display, visibility, etc). Returns true or false.
(displayed? driver q)
Checks whether an element is displayed an screen.
Checks whether an element is displayed an screen.
(doto-wait n obj & body)
The same as doto but prepends each form with (wait n) clause.
The same as doto but prepends each form with (wait n) clause.
(double-click driver q)
Performs double click on an element.
Note:
the supported browsers are Chrome, and Phantom.js.
For Firefox and Safari, your may try to simulate it as a click, wait, click
sequence.
Performs double click on an element. Note: the supported browsers are Chrome, and Phantom.js. For Firefox and Safari, your may try to simulate it as a `click, wait, click` sequence.
(drag-and-drop driver q-from q-to)
Performs drag and drop operation as a sequence of the following steps:
q-from
query;q-to
query;Arguments:
driver
: a driver instance,
q-from
: from what element to start dragging; any expression that
query
function may accept;
q-to
: to what element to drag, a seach term.
Notes:
does not work in Phantom.js since it does not have a virtual mouse API;
does not work in Safari.
Performs drag and drop operation as a sequence of the following steps: 1. moves mouse pointer to an element found with `q-from` query; 2. puts down mouse button; 3. moves mouse to an element found with `q-to` query; 4. puts up mouse button. Arguments: - `driver`: a driver instance, - `q-from`: from what element to start dragging; any expression that `query` function may accept; - `q-to`: to what element to drag, a seach term. Notes: - does not work in Phantom.js since it does not have a virtual mouse API; - does not work in Safari.
(edge? driver)
Returns true if a driver is an Edge instance.
Returns true if a driver is an Edge instance.
(el->ref el)
Turns machinery-wise element ID into an object that Javascript use to reference existing DOM element.
The magic constant below is taken from the standard: https://www.w3.org/TR/webdriver/#elements
Passing such an object to js-execute
automatically expands into a
DOM node. For example:
;; returns long UUID (def el (query driver :button-ok))
;; the first argument will the an Element instance. (js-execute driver "arguments[0].scrollIntoView()", (el->ref el))
Turns machinery-wise element ID into an object that Javascript use to reference existing DOM element. The magic constant below is taken from the standard: https://www.w3.org/TR/webdriver/#elements Passing such an object to `js-execute` automatically expands into a DOM node. For example: ;; returns long UUID (def el (query driver :button-ok)) ;; the first argument will the an Element instance. (js-execute driver "arguments[0].scrollIntoView()", (el->ref el))
(enabled? driver q)
Checks whether an element is enabled.
Checks whether an element is enabled.
(execute {:keys [driver method path data result]})
Executes an HTTP request to a driver's server. Performs the body
within result data bound to the result
clause.
Arguments:
driver
: a driver instance,
method
: a keyword represents HTTP method, e.g. :get
, :post
,
:delete
, etc.
path
: a vector of strings/keywords represents a server's
path. For example:
[:session "aaaa-bbbb-cccc" :element "dddd-eeee" :find]
will turn into "/session/aaaa-bbbb-cccc/element/dddd-eeee/find".
data
: any data sctructure to be sent as JSON body. Put nil
For
GET
requests.
result
: a symbol to bind the data from the HTTP response with
let
form before executing the body.
Example:
(def driver (firefox)) (println (execute {:driver driver :method :get :path [:session (:session @driver) :element :active])))
Executes an HTTP request to a driver's server. Performs the body within result data bound to the `result` clause. Arguments: - `driver`: a driver instance, - `method`: a keyword represents HTTP method, e.g. `:get`, `:post`, `:delete`, etc. - `path`: a vector of strings/keywords represents a server's path. For example: `[:session "aaaa-bbbb-cccc" :element "dddd-eeee" :find]` will turn into "/session/aaaa-bbbb-cccc/element/dddd-eeee/find". - `data`: any data sctructure to be sent as JSON body. Put `nil` For `GET` requests. - `result`: a symbol to bind the data from the HTTP response with `let` form before executing the body. Example: (def driver (firefox)) (println (execute {:driver driver :method :get :path [:session (:session @driver) :element :active])))
(exists? driver q)
Returns true if an element exists on the page.
Keep in mind it does not validates whether the element is visible, clickable and so on.
Returns true if an element exists on the page. Keep in mind it does not validates whether the element is visible, clickable and so on.
(fill driver q text & more)
Fills an element found with a query with a given text.
0.1.6: now the rest parameters are supported. They will joined using "str":
(fill driver :simple-input "foo" "baz" 1) ;; fills the input with "foobaz1"
Fills an element found with a query with a given text. 0.1.6: now the rest parameters are supported. They will joined using "str": (fill driver :simple-input "foo" "baz" 1) ;; fills the input with "foobaz1"
(fill-active driver text & more)
Fills an active element with keys.
Fills an active element with keys.
(fill-el driver el text & more)
Fills an element with text by its identifier.
Fills an element with text by its identifier.
(fill-human driver q text)
Fills text like humans do: with error, corrections and pauses.
Arguments:
driver
: a driver instance,
q
: a query term, see query
function for more info,
text
: a string to input.
Fills text like humans do: with error, corrections and pauses. Arguments: - `driver`: a driver instance, - `q`: a query term, see `query` function for more info, - `text`: a string to input.
(fill-multi driver q-text)
Fills multiple inputs in batch.
q-text
could be:
Fills multiple inputs in batch. `q-text` could be: - a map of {query -> text} - a vector of [query1 text1 query2 text2 ...]
Launches Firefox driver. A shortcut for boot-driver
.
Launches Firefox driver. A shortcut for `boot-driver`.
(firefox-headless)
(firefox-headless opt)
Launches headless Firefox driver. A shortcut for boot-driver
.
Launches headless Firefox driver. A shortcut for `boot-driver`.
(firefox? driver)
Returns true if a driver is a Firefox instance.
Returns true if a driver is a Firefox instance.
(forward driver)
Move forwards in a browser's history.
Move forwards in a browser's history.
Returns a string of text that appears in alert dialog (if present).
Returns a string of text that appears in alert dialog (if present).
(get-cookie driver cookie-name)
Returns the first cookie with such name.
Arguments:
driver
: a driver instance,
cookie-name
: a string/keyword witn a cookie name.
Returns the first cookie with such name. Arguments: - `driver`: a driver instance, - `cookie-name`: a string/keyword witn a cookie name.
(get-cookies driver)
Returns all the cookies browser keeps at the moment.
Each cookie is a map with structure:
{:name "cookie1", :value "test1", :path "/", :domain "", :expiry nil, :secure false, :httpOnly false}
Returns all the cookies browser keeps at the moment. Each cookie is a map with structure: {:name "cookie1", :value "test1", :path "/", :domain "", :expiry nil, :secure false, :httpOnly false}
(get-element-attr driver q name)
Returns an HTTP attribute of an element (class, id, href, etc).
Arguments:
driver
: a driver instance,
q
: a query term to find an element,
name
: either a string or a keyword with a name of an attribute.
Returns: a string with the attribute value, nil
if no such
attribute for that element.
Note: it does not split CSS classes! A single string with spaces is returned.
Example:
(def driver (firefox)) (get-element-attr driver {:tag :a} :class)
"link link__external link__button" ;; see note above
Returns an HTTP attribute of an element (class, id, href, etc). Arguments: - `driver`: a driver instance, - `q`: a query term to find an element, - `name`: either a string or a keyword with a name of an attribute. Returns: a string with the attribute value, `nil` if no such attribute for that element. Note: it does not split CSS classes! A single string with spaces is returned. Example: (def driver (firefox)) (get-element-attr driver {:tag :a} :class) >> "link link__external link__button" ;; see note above
(get-element-attrs driver q & attrs)
Returns multiple attributes in batch. The result is a vector of corresponding attributes.
Returns multiple attributes in batch. The result is a vector of corresponding attributes.
(get-element-box driver q)
Returns a bounding box for an element found with a query term.
The result is a map with the following keys:
:x1
: top left x
coordinate;:y1
: top left y
coordinate;:x2
: bottom right x
coordinate;:y2
: bottom right y
coordinate;:width
: width as a difference b/w :x2
and :x1
;:height
: height as a difference b/w :y2
and :y1
.Returns a bounding box for an element found with a query term. The result is a map with the following keys: - `:x1`: top left `x` coordinate; - `:y1`: top left `y` coordinate; - `:x2`: bottom right `x` coordinate; - `:y2`: bottom right `y` coordinate; - `:width`: width as a difference b/w `:x2` and `:x1`; - `:height`: height as a difference b/w `:y2` and `:y1`.
(get-element-css driver q prop)
Returns a CSS property of an element. The property might be both own or inherited.
Arguments:
driver
: a driver instance,
q
: a query term,
name
: a string/keyword with a CSS name (:font, "background-color", etc).
Returns a string with a value, nil
if there is no such property.
Note: colors, fonts and some other properties may be represented in their own ways depending on a browser.
Example:
(def driver (firefox)) (get-element-css driver {:id :content} :background-color)
"rgb(204, 204, 204)" ;; or "rgba(204, 204, 204, 1)"
Returns a CSS property of an element. The property might be both own or inherited. Arguments: - `driver`: a driver instance, - `q`: a query term, - `name`: a string/keyword with a CSS name (:font, "background-color", etc). Returns a string with a value, `nil` if there is no such property. Note: colors, fonts and some other properties may be represented in their own ways depending on a browser. Example: (def driver (firefox)) (get-element-css driver {:id :content} :background-color) >> "rgb(204, 204, 204)" ;; or "rgba(204, 204, 204, 1)"
(get-element-csss driver q & props)
Returns multiple CSS properties in batch. The result is a vector of corresponding properties.
Returns multiple CSS properties in batch. The result is a vector of corresponding properties.
(get-element-inner-html driver q)
Returns element's inner HTML.
For element el
in <div id="el"><p class="foo">hello</p></div>
it will
be "<p class="foo">hello</p>" string.
Returns element's inner HTML. For element `el` in `<div id="el"><p class="foo">hello</p></div>` it will be "<p class="foo">hello</p>" string.
(get-element-inner-html-el driver el)
Returns element's inner text by its identifier.
Returns element's inner text by its identifier.
(get-element-location driver q)
Returns an element location on a page as a map with :x and :x keys.
Returns an element location on a page as a map with :x and :x keys.
(get-element-properties driver q & props)
Returns multiple properties in batch. The result is a vector of corresponding properties.
Returns multiple properties in batch. The result is a vector of corresponding properties.
(get-element-property driver q name)
Returns a property of an element (value, etc).
Arguments:
driver
: a driver instance,
q
: a query term to find an element,
name
: either a string or a keyword with a name of a property.
Returns: a string with the attribute value, nil
if no such
property for that element.
Returns a property of an element (value, etc). Arguments: - `driver`: a driver instance, - `q`: a query term to find an element, - `name`: either a string or a keyword with a name of a property. Returns: a string with the attribute value, `nil` if no such property for that element.
(get-element-size driver q)
Returns an element size as a map with :width and :height keys.
Returns an element size as a map with :width and :height keys.
(get-element-tag driver q)
Returns element's tag name ("div", "input", etc).
Returns element's tag name ("div", "input", etc).
(get-element-tag-el driver el)
Returns element's tag name by its identifier.
Returns element's tag name by its identifier.
(get-element-text driver q)
Returns inner element's text.
For <p class="foo">hello</p>
it will be "hello" string.
Returns inner element's text. For `<p class="foo">hello</p>` it will be "hello" string.
(get-element-text-el driver el)
Returns element's inner text by its identifier.
Returns element's inner text by its identifier.
(get-element-value driver q)
Returns the current element's value (input text).
Returns the current element's value (input text).
(get-hash driver)
Returns the current hash fragment (nil when not set).
Returns the current hash fragment (nil when not set).
(get-implicit-timeout driver)
Returns the current implicit timeout in seconds.
Returns the current implicit timeout in seconds.
(get-log-types driver)
Returns a set of log types the browser supports.
Returns a set of log types the browser supports.
(get-logs* driver logtype)
Returns Javascript log entries. Each log entry is a map with the following structure:
{:level :warning, :message "1,2,3,4 anonymous (:1)", :timestamp 1511449388366, :source nil, :datetime #inst "2017-11-23T15:03:08.366-00:00"}
Empirical knowledge about browser differences:
:console-api
for :source
field.:source
field.Returns Javascript log entries. Each log entry is a map with the following structure: {:level :warning, :message "1,2,3,4 anonymous (:1)", :timestamp 1511449388366, :source nil, :datetime #inst "2017-11-23T15:03:08.366-00:00"} Empirical knowledge about browser differences: * Chrome: - Returns all recorded logs. - Clears the logs once they have been read. - JS console logs have `:console-api` for `:source` field. - Entries about errors will have SEVERE level. * PhantomJS: - Return all recorded logs since the last URL change. - Does not clear recorded logs on subsequent invocations. - JS console logs have nil for `:source` field. - Entries about errors will have WARNING level, as coded here: https://github.com/detro/ghostdriver/blob/be7ffd9d47c1e76c7bfa1d47cdcde9164fd40db8/src/session.js#L494
(get-page-load-timeout driver)
Returns the current page load timeout in seconds.
Returns the current page load timeout in seconds.
(get-script-timeout driver)
Returns the current script timeout in seconds.
Returns the current script timeout in seconds.
(get-scroll driver)
Returns the current scroll position as a map
with :x
and :y
keys and integer values.
Returns the current scroll position as a map with `:x` and `:y` keys and integer values.
(get-source driver)
Returns browser's current HTML markup as a string.
Returns browser's current HTML markup as a string.
(get-status driver)
Returns the current Webdriver status info. The content depends on specific driver.
Returns the current Webdriver status info. The content depends on specific driver.
(get-title driver)
Returns the current window's title.
Returns the current window's title.
(get-url driver)
Returns the current URL string.
Returns the current URL string.
(get-window-handle driver)
Returns the current active window handler as a string.
Returns the current active window handler as a string.
(get-window-handles driver)
Returns a vector of all window handlers.
Returns a vector of all window handlers.
(get-window-position driver)
Returns a window position relative to your screen as a map with
:x
and :y
keys.
Returns a window position relative to your screen as a map with `:x` and `:y` keys.
(get-window-size driver)
Returns a window size a map with :width
and :height
keys.
Returns a window size a map with `:width` and `:height` keys.
(go driver url)
Open the URL the current window. Example: (def ff (firefox)) (go ff "http://google.com")
(has-alert? driver)
Checks if there is an alert dialog opened on the page.
Checks if there is an alert dialog opened on the page.
(has-class? driver q class)
Checks whether an element has a specific class.
Checks whether an element has a specific class.
(has-text? driver text)
(has-text? driver q text)
Returns true if a passed text appears anywhere on a page. With a leading query expression, finds a text inside the first element that matches the query.
Returns true if a passed text appears anywhere on a page. With a leading query expression, finds a text inside the first element that matches the query.
(headless? driver)
Returns true if a driver is run in headless mode (without UI window).
Returns true if a driver is run in headless mode (without UI window).
(intersects? driver q1 q2)
Determines whether two elements intersects in geometry meaning.
The implementation compares bounding boxes for each element analyzing their arrangement.
Arguments:
q1
and q2
are query terms to find elements to check for
intersection.Returns true or false.
Determines whether two elements intersects in geometry meaning. The implementation compares bounding boxes for each element analyzing their arrangement. Arguments: - `q1` and `q2` are query terms to find elements to check for intersection. Returns true or false.
(join-path p1 p2 & more)
Joins two and more path components into a single file path OS-wisely.
Joins two and more path components into a single file path OS-wisely.
(js-async driver script & args)
Executes an asynchronous script in the browser and returns the result.
An asynchronous script is a such one that performs any kind of IO operations,
say, AJAX request to the server. When running such kind of a script, you cannot
just use the return
statement like you do in ordinary scripts. Instead, the
driver passes a special handler as the last argument that should be called
to return the final result.
Note: calling this function requires the script
timeout to be set properly,
meaning non-zero positive value. See get-script-timeout
, get-script-timeout
and with-script-timeout
functions/macroses.
Example of a script:
// the arguments
would be an array of something like:
// [1, 2, true, ..., <special callback>]
var callback = arguments[arguments.length-1];
// so the main script would look like: $.ajax({url: '/some/url', success: function(result) { if (isResultOk(result)) { callback({ok: getProgressData(result)}); } else { callback({error: getErrorData(result)}); } }});
Arguments:
driver
: a driver instance,
script
: a string with the code to execute.
args
: additional arguments for your code. Any data that might be
serialized into JSON.
Executes an asynchronous script in the browser and returns the result. An asynchronous script is a such one that performs any kind of IO operations, say, AJAX request to the server. When running such kind of a script, you cannot just use the `return` statement like you do in ordinary scripts. Instead, the driver passes a special handler as the last argument that should be called to return the final result. *Note:* calling this function requires the `script` timeout to be set properly, meaning non-zero positive value. See `get-script-timeout`, `get-script-timeout` and `with-script-timeout` functions/macroses. Example of a script: // the `arguments` would be an array of something like: // [1, 2, true, ..., <special callback>] var callback = arguments[arguments.length-1]; // so the main script would look like: $.ajax({url: '/some/url', success: function(result) { if (isResultOk(result)) { callback({ok: getProgressData(result)}); } else { callback({error: getErrorData(result)}); } }}); Arguments: - `driver`: a driver instance, - `script`: a string with the code to execute. - `args`: additional arguments for your code. Any data that might be serialized into JSON.
(js-execute driver script & args)
Executes Javascript code in browser synchronously.
The code is sent as a string (might be multi-line). Under the hood,
a browser wraps your code into a function so avoid using function
clause at the top level.
Don't forget to add return <something>
operator if you are
interested in the result value.
You may access arguments through the built-in arguments
pseudo-array from your code. You may pass any data structures that
are JSON-compatible (scalars, maps, vectors).
The result value is also returned trough JSON encode/decode pipeline (JS objects turn to Clojure maps, arrays into vectors and so on).
Arguments:
driver
: a driver instance,
script
: a string with the code to execute.
args
: additional arguments for your code. Any data that might be
serialized into JSON.
Example:
(def driver (chrome)) (js-execute driver "return arguments[0] + 1;" 42)
43
Executes Javascript code in browser synchronously. The code is sent as a string (might be multi-line). Under the hood, a browser wraps your code into a function so avoid using `function` clause at the top level. Don't forget to add `return <something>` operator if you are interested in the result value. You may access arguments through the built-in `arguments` pseudo-array from your code. You may pass any data structures that are JSON-compatible (scalars, maps, vectors). The result value is also returned trough JSON encode/decode pipeline (JS objects turn to Clojure maps, arrays into vectors and so on). Arguments: - `driver`: a driver instance, - `script`: a string with the code to execute. - `args`: additional arguments for your code. Any data that might be serialized into JSON. Example: (def driver (chrome)) (js-execute driver "return arguments[0] + 1;" 42) >> 43
(left-click driver)
A shortcut for mouse-click
with the left button.
A shortcut for `mouse-click` with the left button.
(left-click-on driver q)
Left mouse click on an element. Probably don't need
that one, use click
instead.
Left mouse click on an element. Probably don't need that one, use `click` instead.
(make-url host port)
Makes an Webdriver URL from a host and port.
Makes an Webdriver URL from a host and port.
(maximize driver)
Makes the browser window as wide as your screen allows.
Makes the browser window as wide as your screen allows.
(middle-click driver)
A shortcut for mouse-click
with the middle button.
A shortcut for `mouse-click` with the middle button.
(middle-click-on driver q)
Move pointer to an element found with a query and middle click on it. Useful for opening links in a new tab.
Move pointer to an element found with a query and middle click on it. Useful for opening links in a new tab.
(mouse-btn-down driver)
Puts down a button of a virtual mouse.
Puts down a button of a virtual mouse.
(mouse-btn-up driver)
Puts up a button of a virtual mouse.
Puts up a button of a virtual mouse.
(mouse-click driver btn)
Click on a mouse button using the current mouse position.
The btn
is a mouse button code. See keys/mouse-*
constants.
Click on a mouse button using the *current* mouse position. The `btn` is a mouse button code. See `keys/mouse-*` constants.
(mouse-click-on driver btn q)
Mouse click on a specific element and a button. Moves the mouse pointer to the element first.
Mouse click on a specific element and a button. Moves the mouse pointer to the element first.
(mouse-move-to driver q)
(mouse-move-to driver x y)
Moves a virtual mouse pointer either to an element
or by x
and y
offset.
Moves a virtual mouse pointer either to an element or by `x` and `y` offset.
Launches Phantom.js driver. A shortcut for boot-driver
.
Launches Phantom.js driver. A shortcut for `boot-driver`.
(phantom? driver)
Returns true if a driver is a Phantom.js instance.
Returns true if a driver is a Phantom.js instance.
(postmortem-handler driver {:keys [dir dir-src dir-img dir-log date-format]})
Internal postmortem handler that creates files.
See the with-postmortem
's docstring below for more info.
Internal postmortem handler that creates files. See the `with-postmortem`'s docstring below for more info.
(process-log entry)
Remaps some of the log's fields.
Remaps some of the log's fields.
(query driver q)
(query driver q & more)
Finds an element on a page.
A query might be:
:active
that means to get the current active element;:xpath
or :css
key with a string value
of corresponding selector type (XPath or CSS);Returns a element's unique identifier.
Finds an element on a page. A query might be: - a string with an XPath expression; - a keyword `:active` that means to get the current active element; - any other keyword which stands for an element's ID attribute; - a map with either `:xpath` or `:css` key with a string value of corresponding selector type (XPath or CSS); - any other map that will be expanded into XPath term (see README.md); - a vector of any expressions mentioned above. In that case, each next term is searched from the previous one. Returns a element's unique identifier.
(query-all driver q)
(query-all driver q & more)
Finds multiple elements on a page.
See query
function for incoming params.
Returns a vector of element identifiers.
Finds multiple elements on a page. See `query` function for incoming params. Returns a vector of element identifiers.
(quit driver)
Closes the current session and stops the driver.
Closes the current session and stops the driver.
(refresh driver)
Reloads the current window.
Reloads the current window.
(right-click driver)
A shortcut for mouse-click
with the right button.
A shortcut for `mouse-click` with the right button.
(right-click-on driver q)
Move pointer to an element found with a query and right click on it.
Move pointer to an element found with a query and right click on it.
(run-driver driver
&
[{:keys [dev env url args size prefs profile headless log-level
args-driver path-driver download-dir path-browser
load-strategy]}])
Runs a driver process locally.
Creates a UNIX process with a Webdriver HTTP server. Host and port
are taken from a driver
argument. Updates a driver instance with
new fields with process information. Returns modified driver.
Arguments:
driver
is an atom created with create-driver
function.
opt
is an optional map with the following possible parameters:
-- :path-driver
is a string path to the driver's binary file. When
not passed, it is taken from defaults.
-- :path-browser
is a string path to the browser's binary
file. When not passed, the driver discovers it by its own.
-- :size
is a vector of two integers specifying initial window size.
-- :url
is a string with the default URL opened by default (FF only for now).
-- :log-level
a keyword to set browser's log level. Used when fetching
browser's logs. Possible values are: :off
, :debug
, :warn
, :info
,
:error
, :all
. When not passed, :all
is set.
-- :profile
is a string path that points on profile folder.
See the Setting browser profile
section in README.md
to know
how to do it properly.
-- :load-strategy
is a string or keyword with specifying
what strategy to use when load a page. Might be :none
, :eager
or :normal
(default). To not wait the page being loaded completely,
specify :none
. The :eager
option is still under development
in most of the browser.
-- headless
is a boolean flag to run the browser in headless mode
(i.e. without GUI window). Useful when running tests on CI servers
rather than local machine. Currently, only FF and Chrome support headless mode.
Phantom.js is headless by its nature.
-- :args
is a vector of additional command line arguments
to the browser's process.
-- :prefs
is a map of browser-specific preferences.
-- :args-driver
is a vector of additional arguments to the
driver's process.
-- :env
is a map with system ENV variables. Keys are turned into
upper-case strings.
Runs a driver process locally. Creates a UNIX process with a Webdriver HTTP server. Host and port are taken from a `driver` argument. Updates a driver instance with new fields with process information. Returns modified driver. Arguments: - `driver` is an atom created with `create-driver` function. - `opt` is an optional map with the following possible parameters: -- `:path-driver` is a string path to the driver's binary file. When not passed, it is taken from defaults. -- `:path-browser` is a string path to the browser's binary file. When not passed, the driver discovers it by its own. -- `:size` is a vector of two integers specifying initial window size. -- `:url` is a string with the default URL opened by default (FF only for now). -- `:log-level` a keyword to set browser's log level. Used when fetching browser's logs. Possible values are: `:off`, `:debug`, `:warn`, `:info`, `:error`, `:all`. When not passed, `:all` is set. -- `:profile` is a string path that points on profile folder. See the `Setting browser profile` section in `README.md` to know how to do it properly. -- `:load-strategy` is a string or keyword with specifying what strategy to use when load a page. Might be `:none`, `:eager` or :`normal` (default). To not wait the page being loaded completely, specify `:none`. The `:eager` option is still under development in most of the browser. -- `headless` is a boolean flag to run the browser in headless mode (i.e. without GUI window). Useful when running tests on CI servers rather than local machine. Currently, only FF and Chrome support headless mode. Phantom.js is headless by its nature. -- `:args` is a vector of additional command line arguments to the browser's process. -- `:prefs` is a map of browser-specific preferences. -- `:args-driver` is a vector of additional arguments to the driver's process. -- `:env` is a map with system ENV variables. Keys are turned into upper-case strings.
(running? driver)
Check whether a driver runs HTTP server.
Check whether a driver runs HTTP server.
Launches Safari driver. A shortcut for boot-driver
.
Launches Safari driver. A shortcut for `boot-driver`.
(safari? driver)
Returns true if a driver is a Safari instance.
Returns true if a driver is a Safari instance.
(screenshot driver file)
Takes a screenshot of the current page. Saves it in a *.png file on disk. Rises exception if a screenshot was empty.
Arguments:
driver
: driver instance,
file
: either a path to a file or a native java.io.File
instance.
Takes a screenshot of the current page. Saves it in a *.png file on disk. Rises exception if a screenshot was empty. Arguments: - `driver`: driver instance, - `file`: either a path to a file or a native `java.io.File` instance.
(scroll driver {:keys [x y]})
(scroll driver x y)
Scrolls the window into absolute position (jumps to exact place).
Scrolls the window into absolute position (jumps to exact place).
(scroll-bottom driver)
Scrolls to bottom of the page keeping current horizontal position.
Scrolls to bottom of the page keeping current horizontal position.
(scroll-by driver {:keys [x y]})
(scroll-by driver x y)
Scrolls the window by offset (relatively the current position).
Scrolls the window by offset (relatively the current position).
(scroll-down driver)
(scroll-down driver offset)
Scrolls the page down by specific number of pixels.
The scroll-offset
constant is used when not passed.
Scrolls the page down by specific number of pixels. The `scroll-offset` constant is used when not passed.
(scroll-left driver)
(scroll-left driver offset)
Scrolls the page left by specific number of pixels.
The scroll-offset
constant is used when not passed.
Scrolls the page left by specific number of pixels. The `scroll-offset` constant is used when not passed.
Default scroll offset in pixels.
Default scroll offset in pixels.
(scroll-query driver q)
(scroll-query driver q param)
Scrolls to the first element found with a query.
Invokes element's .scrollIntoView()
method. Accepts extra param
argument that might be either boolean or object for more control.
See this page for details: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
Scrolls to the first element found with a query. Invokes element's `.scrollIntoView()` method. Accepts extra `param` argument that might be either boolean or object for more control. See this page for details: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
(scroll-right driver)
(scroll-right driver offset)
Scrolls the page right by specific number of pixels.
The scroll-offset
constant is used when not passed.
Scrolls the page right by specific number of pixels. The `scroll-offset` constant is used when not passed.
(scroll-top driver)
Scrolls to top of the page keeping current horizontal position.
Scrolls to top of the page keeping current horizontal position.
(scroll-up driver)
(scroll-up driver offset)
Scrolls the page up by specific number of pixels.
The scroll-offset
constant is used when not passed.
Scrolls the page up by specific number of pixels. The `scroll-offset` constant is used when not passed.
(set-cookie driver cookie)
Sets a new cookie.
Arguments:
driver
: a driver instance,
cookie
: a map with structure described in get-cookies
. At
least :name
and :value
fields should be populated.
Sets a new cookie. Arguments: - `driver`: a driver instance, - `cookie`: a map with structure described in `get-cookies`. At least `:name` and `:value` fields should be populated.
(set-hash driver hash)
Sets a new hash fragment for the current page. Don't include the leading # symbol. Useful when navigating on single page applications.
Sets a new hash fragment for the current page. Don't include the leading # symbol. Useful when navigating on single page applications.
(set-implicit-timeout driver sec)
Sets timeout that is used when finding elements on the page.
Sets timeout that is used when finding elements on the page.
(set-page-load-timeout driver sec)
Sets timeout for loading pages.
Sets timeout for loading pages.
(set-script-timeout driver sec)
Sets timeout for executing JS sctipts.
Sets timeout for executing JS sctipts.
(set-window-position driver {:keys [x y]})
(set-window-position driver x y)
Sets new position for a window. Absolute precision is not guaranteed.
Sets new position for a window. Absolute precision is not guaranteed.
(set-window-size driver {:keys [width height]})
(set-window-size driver width height)
Sets new size for a window. Absolute precision is not guaranteed.
Sets new size for a window. Absolute precision is not guaranteed.
(stop-driver driver)
Stops the driver's process. Removes proces's data from the driver instance. Returns a modified driver.
Stops the driver's process. Removes proces's data from the driver instance. Returns a modified driver.
(submit driver q)
Sends Enter button value to an element found with query.
Sends Enter button value to an element found with query.
(supports-logs? driver)
Checks whether a driver supports getting console logs.
Checks whether a driver supports getting console logs.
(switch-frame driver q)
Switches to an (i)frame quering the page for it.
Switches to an (i)frame quering the page for it.
(switch-frame* driver id)
Switches to an (i)frame by its index or an element reference.
Switches to an (i)frame by its index or an element reference.
(switch-frame-first driver)
Switches to the first (i)frame.
Switches to the first (i)frame.
(switch-frame-parent driver)
Switches to the parent of the current (i)frame.
Switches to the parent of the current (i)frame.
(switch-frame-top driver)
Switches to the most top of the page.
Switches to the most top of the page.
(switch-window driver handle)
Switches a browser to another window.
Switches a browser to another window.
Attaches a local file to a file input field.
Arguments:
q
is a query term that refers to a file input;file
is either a string or java.io.File object
that references a local file. The file should exist.Under the hood, it sends the file's name as a sequence of keys to the input.
Attaches a local file to a file input field. Arguments: - `q` is a query term that refers to a file input; - `file` is either a string or java.io.File object that references a local file. The file should exist. Under the hood, it sends the file's name as a sequence of keys to the input.
(visible? driver q)
Checks whether an element is visible on the page.
Checks whether an element is visible on the page.
(wait-absent driver q & [opt])
Waits until an element is absent.
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element is absent. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-disabled driver q & [opt])
Waits until an element is disabled (usually an input element).
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element is disabled (usually an input element). Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-enabled driver q & [opt])
Waits until an element is enabled (usually an input element).
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element is enabled (usually an input element). Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-exists driver q & [opt])
Waits until an element exists on a page (but may not be visible though).
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element exists on a page (but may not be visible though). Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-has-alert driver & [opt])
Waits until an alert dialog appears on the screen.
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an alert dialog appears on the screen. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-has-class driver q class & [opt])
Waits until an element has specific class.
Arguments:
driver
: a driver instance;q
: a query term (see query
);class
: a class to search as string;opt
: a map of options (see wait-predicate
).Waits until an element has specific class. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `class`: a class to search as string; - `opt`: a map of options (see `wait-predicate`).
(wait-has-text driver q text & [opt])
Waits until an element has text anywhere inside it (including inner HTML).
Arguments:
driver
: a driver instance;q
: a query term (see query
);text
: a string to search;opt
: a map of options (see wait-predicate
).Waits until an element has text anywhere inside it (including inner HTML). Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `text`: a string to search; - `opt`: a map of options (see `wait-predicate`).
(wait-invisible driver q & [opt])
Waits until an element presents but not visible.
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element presents but not visible. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(wait-predicate pred)
(wait-predicate pred opt)
Sleeps continuously calling a predicate until it returns true. Raises a slingshot exception when timeout is reached.
Arguments:
pred
: a zero-argument predicate to call;opt
: a map of optional parameters:
-- :timeout
wait limit in seconds, 20 by default;
-- :interval
how long to wait b/w calls, 0.33 by default;
-- :message
a message that becomes a part of exception when timeout is reached.Sleeps continuously calling a predicate until it returns true. Raises a slingshot exception when timeout is reached. Arguments: - `pred`: a zero-argument predicate to call; - `opt`: a map of optional parameters: -- `:timeout` wait limit in seconds, 20 by default; -- `:interval` how long to wait b/w calls, 0.33 by default; -- `:message` a message that becomes a part of exception when timeout is reached.
(wait-visible driver q & [opt])
Waits until an element presents and is visible.
Arguments:
driver
: a driver instance;q
: a query term (see query
);opt
: a map of options (see wait-predicate
).Waits until an element presents and is visible. Arguments: - `driver`: a driver instance; - `q`: a query term (see `query`); - `opt`: a map of options (see `wait-predicate`).
(when-chrome driver & body)
Executes the body only if the driver is Chrome.
Example:
(def driver (chrome)) (when-chrome driver (println "It's Chrome!")
Executes the body only if the driver is Chrome. Example: (def driver (chrome)) (when-chrome driver (println "It's Chrome!")
(when-firefox driver & body)
Executes the body only if the driver is Firefox.
Executes the body only if the driver is Firefox.
(when-headless driver & body)
Executes the body only if the driver is run in headless mode.
Executes the body only if the driver is run in headless mode.
(when-not-chrome driver & body)
Executes the body only if a browser is NOT Chrome.
Executes the body only if a browser is NOT Chrome.
(when-not-edge driver & body)
Executes the body only if a browser is NOT Edge.
Executes the body only if a browser is NOT Edge.
(when-not-firefox driver & body)
Executes the body only if a browser is NOT Firefox.
Executes the body only if a browser is NOT Firefox.
(when-not-headless driver & body)
Executes the body only if a browser is NOT run in headless mode.
Executes the body only if a browser is NOT run in headless mode.
(when-not-phantom driver & body)
Executes the body only if a browser is NOT Phantom.js.
Executes the body only if a browser is NOT Phantom.js.
(when-not-safari driver & body)
Executes the body only if a browser is NOT Safari.
Executes the body only if a browser is NOT Safari.
(when-phantom driver & body)
Executes the body only if the driver is Phantom.js.
Executes the body only if the driver is Phantom.js.
(when-predicate predicate & body)
Executes the body only if a predicate returns true.
Executes the body only if a predicate returns true.
(when-safari driver & body)
Executes the body only if the driver is Safari.
Executes the body only if the driver is Safari.
(with-chrome opt bind & body)
Performs the body with Chrome session. A shortcut for
with-driver
.
Performs the body with Chrome session. A shortcut for `with-driver`.
(with-chrome-headless opt bind & body)
Performs the body with headless Chrome session. A shortcut for
with-driver
.
Performs the body with headless Chrome session. A shortcut for `with-driver`.
(with-driver type opt bind & body)
Performs the body within a driver session.
Launches a driver of a given type. Binds the driver instance to a
passed bind
symbol. Executes the body once the driver has
started. Shutdowns the driver finally (even if an exception
occurred).
Arguments:
type
is a keyword what driver type to start.
opt
is a map with driver's options. See boot-driver
for more
details.
bind
is a symbol to bind a driver reference.
Example:
(with-driver :firefox {} driver (go driver "http://example.com"))
Performs the body within a driver session. Launches a driver of a given type. Binds the driver instance to a passed `bind` symbol. Executes the body once the driver has started. Shutdowns the driver finally (even if an exception occurred). Arguments: - `type` is a keyword what driver type to start. - `opt` is a map with driver's options. See `boot-driver` for more details. - `bind` is a symbol to bind a driver reference. Example: (with-driver :firefox {} driver (go driver "http://example.com"))
(with-edge opt bind & body)
Performs the body with Edge session. A shortcut for
with-driver
.
Performs the body with Edge session. A shortcut for `with-driver`.
(with-firefox opt bind & body)
Performs the body with Firefox session. A shortcut for
with-driver
.
Performs the body with Firefox session. A shortcut for `with-driver`.
(with-firefox-headless opt bind & body)
Performs the body with headless Firefox session. A shortcut for
with-driver
.
Performs the body with headless Firefox session. A shortcut for `with-driver`.
(with-frame driver q & body)
Switches to the (i)frame temporary while executing the body returning the result of the last expression.
Switches to the (i)frame temporary while executing the body returning the result of the last expression.
(with-mouse-btn driver & body)
Performs the body keeping mouse botton pressed.
Performs the body keeping mouse botton pressed.
(with-phantom opt bind & body)
Performs the body with Phantom.js session. A shortcut for
with-driver
.
Performs the body with Phantom.js session. A shortcut for `with-driver`.
(with-postmortem driver opt & body)
Wraps the body with postmortem handler. If any error occurs, it will save a screenshot, the page's source code and console logs (if supported) on disk before rising an exception. Having them could help you to discover what happened.
Note: do not use it in test's fixtures. The standard clojure.test
framework has its own way of handling exceptions, so wrapping a fixture
with (with-postmortem...)
would be in vain.
Arguments:
driver
: a driver instance,
opt
: a map of options, where:
-- :dir
path to a directory where to store artifacts by default.
When not passed, the current working directory (pwd
) is used.
-- :dir-img
: path to a directory where to store .png
files (screenshots). If nil
, :dir
value is used.
-- :dir-src
: path to a directory where to store .html
files (page source). If nil
, :dir
value is used.
-- :dir-log
: path to a directory where to store .json
files with console logs. If nil
, :dir
value is used.
-- :date-format
: a string represents date(time) pattern to make
filenames unique. Default is "yyyy-MM-dd-HH-mm-ss". See Oracle
Java SimpleDateFormat
class manual for more patterns.
Wraps the body with postmortem handler. If any error occurs, it will save a screenshot, the page's source code and console logs (if supported) on disk before rising an exception. Having them could help you to discover what happened. Note: do not use it in test's fixtures. The standard `clojure.test` framework has its own way of handling exceptions, so wrapping a fixture with `(with-postmortem...)` would be in vain. Arguments: - `driver`: a driver instance, - `opt`: a map of options, where: -- `:dir` path to a directory where to store artifacts by default. When not passed, the current working directory (`pwd`) is used. -- `:dir-img`: path to a directory where to store `.png` files (screenshots). If `nil`, `:dir` value is used. -- `:dir-src`: path to a directory where to store `.html` files (page source). If `nil`, `:dir` value is used. -- `:dir-log`: path to a directory where to store `.json` files with console logs. If `nil`, `:dir` value is used. -- `:date-format`: a string represents date(time) pattern to make filenames unique. Default is "yyyy-MM-dd-HH-mm-ss". See Oracle Java `SimpleDateFormat` class manual for more patterns.
(with-safari opt bind & body)
Performs the body with Safari session. A shortcut for
with-driver
.
Performs the body with Safari session. A shortcut for `with-driver`.
(with-script-timeout driver sec & body)
Performs the body setting the script timeout temporary. Useful for async JS scripts.
Performs the body setting the script timeout temporary. Useful for async JS scripts.
(with-wait n & body)
Executes the body waiting for n seconds before each form. Returns a value of the last form. Use that macros to perform a bunch of actions slowly. Some SPA applications need extra time to re-render the content.
Executes the body waiting for n seconds before each form. Returns a value of the last form. Use that macros to perform a bunch of actions slowly. Some SPA applications need extra time to re-render the content.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close