Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Taxi API Documentation

Antti Virtanen edited this page May 16, 2016 · 18 revisions

Table of contents


add-cookie

(add-cookie cookie-spec)
(add-cookie driver cookie-spec)
Add a cookie to the browser session. The `cookie-spec` is a map which must contain `:name` and `:value` keys, and can also optionally include `:domain`, `:path`, `:expiry`, and `:secure?` (a boolean).

Examples:

;; ;; Simple example ;; (add-cookie {:name "foo", :value "bar"})

;; ;; Full example ;; (add-cookie {:name "foo", :value "bar", :domain "example.com", :path "a-path", :expiry (java.util.Date.), :secure? false})

attribute

(attribute q attr)
(attribute driver q attr)
For the first element found with query q, return the value of the given attribute.

Examples:

;; ;; Example medley for an anchor tag with id "foo", class "bar", and target "_blank" ;; (attribute "a#foo" :id) ;=> "foo" (attribute "a#foo" :class) ;=> "bar" (attribute "a#foo" :target) ;=> "_blank"

back

(back)
(back n)
(back driver n)
Navigate back in the browser history, optionally n times.

Examples:

;; ;; Simple Example ;; (back)

;; ;; Specify number of times to go back ;; (back 2)

clear

(clear q)
(clear driver q)
Clear the contents (the HTML value attribute) of the first form element found with query q.

Examples:

(clear "input.with-default-text")

click

(click q)
(click driver q)
Click the first element found with query q.

Examples:

(click "a#foo")

close

(close)
(close driver)
Close the browser. If multiple windows are open, this only closes the active window.

Examples:

(close)

cookie

(cookie cookie-name)
(cookie driver cookie-name)
Return the cookie with name cookie-name. Returns a Cookie record which contains a :cookie field with the original Java object.

Examples:

(cookie "foo")

cookies

(cookies)
(cookies driver)
Return a seq of all cookies in the browser session. Items are Cookie records, which themselves contain a :cookie field with the original Java objects.

Examples:

(cookies)

css-finder

(css-finder q)
(css-finder driver q)
Given a CSS query q, return a lazy seq of the elements found by calling find-elements with by-css. If q is an Element, it is returned unchanged.

This function is used internally by the Taxi API as *finder*. See the documentation for set-finder! for examples of extending this function or creating your own custom finder function.

current-url

(current-url)
(current-url driver)
Return the current url of the browser.

Examples:

(current-url)

delete-all-cookies

(delete-all-cookies)
(delete-all-cookies driver)
Delete all cookies from the browser session.

Examples:

(delete-all-cookies)

delete-cookie

(delete-cookie name-or-obj)
(delete-cookie driver name-or-obj)
Provided the name of a cookie or a Cookie record itself, delete it from the browser session.

Examples:

;; ;; By name ;; (delete-cookie "foo")

;; ;; With Cookie record as returned by cookies or cookie functions ;; (delete-cookie a-cookie)

deselect

(deselect q)
(deselect driver q)
If the first form element found with query q is selected, click the element to deselect it. Otherwise, do nothing and just return the element found.

Examples:

(deselect "input.already-selected") ;=> click (deselect "input.not-selected") ;=> do nothing

deselect-all

(deselect-all q)
(deselect-all driver q)
Deselect all options within the first select list found with query q.

Examples:

(deselect-all "#my-select-list")

deselect-by-index

(deselect-by-index q idx)
(deselect-by-index driver q idx)
Deselect the option element at index idx (zero-based) within the first select list found with query q.

Examples:

;; ;; Deselect by index, deselect 2nd element ;; (deselect-by-index "#my-select-list" 1)

deselect-by-text

(deselect-by-text q text)
(deselect-by-text driver q text)
Deselect the option element with visible text text within the first select list found with query q.

Examples:

(deselect-by-text "#my-select-list" "Foo")

deselect-by-value

(deselect-by-value q value)
(deselect-by-value driver q value)
Deselect the option element with value within the first select list found with query q.

Examples:

(deselect-by-value "#my-select-list" "foo")

deselect-option

(deselect-option q attr-val)
(deselect-option driver q attr-val)
Deselect the option element matching attr-val within the first select list found with query q.

The attr-val can contain :index, :value, or :text keys to find the target option element. Index is the zero-based order of the option element in the list, value is the value of the HTML value attribute, and text is the visible text of the option element on the page.

Examples:

;; ;; By index, select 3rd option element ;; (deselect-option "#my-select-list" {:index 2})

;; ;; By value of option element ;; (deselect-option "#my-select-list" {:value "foo"})

;; ;; By visible text of option element ;; (deselect-option "#my-select-list" {:value "Foo"})

displayed?

(displayed? q)
(displayed? driver q)
Return true if the first element found with query q is visible on the page.

Examples:

(displayed? "div#container") ;=> true (displayed? "a.hidden") ;=> false

drag-and-drop

(drag-and-drop qa qb)
(drag-and-drop driver qa qb)
Drag the first element found with query qa onto the first element found with query qb.

Examples:

;; ;; Drag div with id "draggable" onto div with id "droppable" ;; (drag-and-drop "#draggable" "#droppable")

drag-and-drop-by

(drag-and-drop-by q x-y-map)
(drag-and-drop-by driver q x-y-map)
Drag the first element found with query q by :x pixels to the right and :y pixels down, passed in as a map like {:x 10, :y 10}. Values default to zero if excluded. Use negative numbers for :x and :y to move left or up respectively.

Examples:

;; ;; Drag a div with id "draggable" 20 pixels to the right ;; (drag-and-drop-by "#draggable" {:x 20})

;; ;; Drag a div with id "draggable" 10 pixels down ;; (drag-and-drop-by "#draggable" {:y 10})

;; ;; Drag a div with id "draggable" 15 pixels to the left and 5 pixels up ;; (drag-and-drop-by "#draggable" {:x -15, :y -5})

element

(element q)
(element driver q)
Given a query q, return the first element that the default finder function returns.

Examples:

;; ;; Simple Example ;; ;; Create a var that points to an element for later use. ;; (def login-link (element "a[href*='login']"))

;; ;; More useful example: composing actions on an element ;; ;; When threading actions together, it's more performant to thread an actual element, ;; than to thread simply the query string. Threading the query string makes clj-webdriver ;; locate the same element multiple times, while threading an actual element only ;; requires one lookup. ;; (-> (element "input#password") (input-text "my-password") submit)

elements

(elements q)
(elements driver q)
Given a query q, return the elements that the default finder function returns.

Examples:

;; ;; Simple Example ;; ;; Save a seq of anchor tags (links) for later. ;; (def target-elements (elements "a"))

element-size

(element-size q)
(element-size driver q)
Return the size of the first element found with query q in pixels as a map of :width and :height..

Examples:

(element-size "div#container") ;=> {:width 960, :height 2000}

enabled?

(enabled? q)
(enabled? driver q)
Return true if the first form element found with query q is enabled (not disabled).

Examples:

(enabled? "input") ;=> true (enabled? "input[disabled='disabled']") ;=> false

execute-script

(execute-script js & js-args)
Execute the JavaScript code js with arguments js-args.

Within the script, use document to refer to the current document. Note that local variables will not be available once the script has finished executing, though global variables will persist.

If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken:

  • For an HTML element, this method returns a WebElement
  • For a decimal, a Double is returned
  • For a non-decimal number, a Long is returned
  • For a boolean, a Boolean is returned
  • For all other cases, a String is returned.
  • For an array, return a List<Object> with each object following the rules above. We support nested lists.
  • Unless the value is null or there is no return value, in which null is returned.

Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the 'arguments' magic variable, as if the function were called via 'Function.apply'

See http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.html#executeScript(java.lang.String, java.lang.Object...) for full details.

Examples:

;; ;; Set a global variable ;; (execute-script "window.document.title = 'asdf'")

;; ;; Return an element. Note that this currently returns a raw WebElement Java object. ;; (execute-script "var myElement = document.getElementById('elementId'); return myElement;")

exists?

(exists? q)
(exists? driver q)
Return true if the first element found with query q exists on the current page in the browser.

Examples:

(exists? "a#foo") ;=> true (exists? "footer") ;=> false

find-element

(find-element attr-val)
(find-element driver attr-val)
Return first Element record that matches the given attr-val. Prefer the default behavior of element when possible.

Whereas the element function uses a query q with the default finder function, this function requires an attr-val parameter which is either a map or a vector of maps with special semantics for finding elements on the page.

The attr-val map can consist of one or more of the following:

  • The key :css or :xpath and a query value (e.g., {:css "a.external"})
  • The key :tag and an HTML tag (e.g., {:tag :a})
  • An HTML element attribute and its value (e.g., {:class "external"})
  • A 'meta' tag :button*, :radio, :checkbox, :textfield, :password, :filefield (e.g., {:tag :button*})
  • The key :index and the zero-based index (order) of the target element on the page (e.g., {:index 2} retrieves the third element that matches)
  • A vector of attr-val maps like the above, representing a hierarchical query (auto-generates XPath)

Examples:

;; ;; Medley of possibilities ;; (find-element {:css "a.foo"}) (find-element {:xpath "//a[@class='foo']"}) (find-element {:tag :a, :text "Login"}) (find-element {:tag :a, :index 4}) ;; 5th anchor tag (find-element {:tag :button*, :class "foo"}) (find-element {:tag :radio, :class "choice"}) (find-element [{:tag :div, :id "container"}, {:tag :a, :class "external"}])

find-element-under

(find-element-under q-parent attr-val)
Find the first element that is a child of the element found with query q-parent, using the given attr-val. If q-parent is an Element, it will be used as-is. The attr-val can either be a find-element-style map of attributes and values, or a by-clause (by-tag, by-class, etc.)

Note that this function is intended to fit better with find-element by allowing a full attr-val map instead of a by-clause, which will be implemented pending a re-write of find-elements.

Examples:

;; ;; Example using map, which generates a (by-xpath ...) form ;; (find-element-under "div#container" {:tag :a, :id "foo"})

;; ;; Example using by-clause, find an element with id "foo" within a div with id "container" ;; (find-element-under "div#container" (core/by-id "foo")

find-elements

(find-elements attr-val)
(find-elements driver attr-val)
Return Element records that match the given attr-val. Prefer the default behavior of elements when possible.

Whereas the elements function uses a query q with the default finder function, this function requires an attr-val parameter which is either a map or a vector of maps with special semantics for finding elements on the page.

The attr-val map can consist of one or more of the following:

  • The key :css or :xpath and a query value (e.g., {:css "a.external"})
  • The key :tag and an HTML tag (e.g., {:tag :a})
  • An HTML element attribute and its value (e.g., {:class "external"})
  • A 'meta' tag :button*, :radio, :checkbox, :textfield, :password, :filefield (e.g., {:tag :button*})
  • The key :index and the zero-based index (order) of the target element on the page (e.g., {:index 2} retrieves the third element that matches)
  • A vector of attr-val maps like the above, representing a hierarchical query (auto-generates XPath)

Examples:

;; ;; Medley of possibilities ;; (find-elements {:css "a.foo"}) (find-elements {:xpath "//a[@class='foo']"}) (find-elements {:tag :a, :text "Login"}) (find-elements {:tag :a, :index 4}) ;; 5th anchor tag (find-elements {:tag :button*, :class "foo"}) (find-elements {:tag :radio, :class "choice"}) (find-elements [{:tag :div, :id "container"}, {:tag :a, :class "external"}])

find-elements-under

(find-elements-under q-parent attr-val)
Find the elements that are children of the element found with query q-parent, using the given attr-val. If q-parent is an Element, it will be used as-is. The attr-val can either be a find-element-style map of attributes and values, or a by-clause (by-tag, by-class, etc.)

Examples:

;; ;; Example using a map ;; (find-elements-under "div#container" {:tag :a, :id "foo"})

;; ;; Example using by-clause, find an element with id "foo" within a div with id "container" ;; (find-elements-under "div#container" (core/by-id "foo")

find-table-cell

(find-table-cell table-q coords)
(find-table-cell driver table-q coords)
Within the table found with query table-q, return the table cell at coordinates coords. The top-left cell has coordinates [0 0].

Examples:

;; ;; Simple example, find 2nd cell on 2nd row from top ;; (find-table-cell "table#my-table" [1 1])

find-table-row

(find-table-row table-q row)
(find-table-row driver table-q row)
Within the table found with query table-q, return a seq of all cells at row number row. The top-most row is row 0 (zero-based index).

Examples:

;; ;; Simple example, return cells in second row ;; (find-table-row "table#my-table" 1)

find-window

(find-window attr-val)
(find-window driver attr-val)
Return the first WindowHandle record that matches the given attr-val map.

Attributes can be anything in a WindowHandle record (:title or :url) or you can pass an :index key and a number value to select a window by its open order.

Examples:

;; ;; By name ;; (find-window {:title "Window Title"})

;; ;; By URL ;; (find-window {:url "http://example.com/test-page"})

;; ;; By index ;; (find-window {:index 2})

find-windows

(find-windows attr-val)
(find-windows driver attr-val)
Return all WindowHandle records that match the given attr-val map.

Attributes can be anything in a WindowHandle record (:title or :url) or you can pass an :index key and a number value to select a window by its open order.

Examples:

;; ;; By name ;; (find-windows {:title "Window Title"})

;; ;; By URL ;; (find-windows {:url "http://example.com/test-page"})

;; ;; By index ;; (find-windows {:index 2})

flash

(flash q)
(flash driver q)
Flash the background color of the first element found with query q.

Examples:

(flash "a.hard-to-see")

focus

(focus q)
(focus driver q)
Explicitly give the first element found with query q focus on the page.

Examples:

(focus "input.next-element")

forward

(forward)
(forward n)
(forward driver n)
Navigate forward in the browser history.

Examples:

;; ;; Simple Example ;; (forward)

;; ;; Specify number of times to go back ;; (forward 2)

get-url

(get-url url)
(get-url driver url)
Navigate the browser to url.

Examples:

;; ;; Simple Example ;; (get-url "https://github.com")

;; ;; Custom function for building URL's from a base url ;; (defn go [path] (let [base-url "http://example.com/"] (get-url (str base-url path)))) ;; (go "test-page") would navigate to "http://example.com/test-page"

html

(html q)
(html driver q)
Return the inner html of the first element found with query q.

Examples:

(html "div.with-interesting-html")

implicit-wait

(implicit-wait timeout)
(implicit-wait driver timeout)
Set the global timeout that the browser should wait when attempting to find elements on the page, before timing out with an exception.

Examples:

;; ;; Simple example (taken from unit tests) ;; ;; Set implicit timeout (global) to 3 seconds, then execute JavaScript with a ;; noticeable delay to prove that it works ;; (implicit-wait 3000) (execute-script "setTimeout(function () { window.document.body.innerHTML = '<div id='test'>hi!</div>'}, 1000)")

input-text

(input-text q s)
(input-text driver q s)
Type the string s into the first form element found with query q.

Examples:

(input-text "input#login_field" "semperos")

intersect?

(intersect? qa qb)
(intersect? driver qa qb)
Return true if the first element found with query qa intersects with the first element found with query qb.

Examples:

(intersect? "#login" "#login_field") ;=> true (intersect? "#login_field" "#password") ;=> false

location

(location q)
(location driver q)
Return a map of :x and :y coordinates for the first element found with query q.

Examples:

(location "a#foo") ;=> {:x 240, :y 300}

location-once-visible

(location-once-visible q)
(location-once-visible driver q)
Return a map of :x and :y coordinates for the first element found with query q once the page has been scrolled enough to be visible in the viewport.

Examples:

(location-once-visible "a#foo") ;=> {:x 240, :y 300}

multiple?

(multiple? q)
(multiple? driver q)
Return true if the first select list found with query q allows multiple selections.

Examples:

(multiple? "select.multiple") ;=> true (multiple? "select.not-multiple") ;=> false

options

(options q)
(options driver q)
Return all option elements within the first select list found with query q.

Examples:

(options "#my-select-list")

other-windows

(other-windows)
(other-windows driver)
Return a Window for all open windows except the active one.

Examples:

(other-windows)

page-source

(page-source)
(page-source driver)
Return the source code of the current page in the browser.

Examples:

;; ;; Simple Example ;; (page-source)

;; ;; Do something with the HTML ;; ;; Selenium-WebDriver will instantiate a Java object for every element you query ;; or interact with, so if you have huge pages or need to do heavy-duty DOM ;; inspection or traversal, it could be more performant to do that "offline". ;; (let [source (page-source)] ;; do hard-core parsing and manipulation here )

present?

(present? q)
(present? driver q)
Return true if the first element found with query q both exists and is visible on the page.

Examples:

(present? "div#container") ;=> true (present? "a#skip-to-navigation") ;=> false

quick-fill

(quick-fill & query-action-maps)
A utility for filling out multiple fields in a form in one go. Returns all the affected elements (if you want a list of unique elements, pass the results through the distinct function in clojure.core).

query-action-maps - a seq of maps of queries to actions (queries find HTML elements, actions are fn's that act on them)

Note that an "action" that is just a String will be interpreted as a call to input-text with that String for the target text field.

Examples:

(quick-fill {"#first_name" "Rich"} {"a.foo" click})

quick-fill-submit

(quick-fill-submit & query-action-maps)
A utility for filling out multiple fields in a form in one go. Always returns nil instead of the affected elements, since on submit all of the elements will be void.

query-action-maps - a seq of maps of queries to actions (queries find HTML elements, actions are fn's that act on them)

Note that an "action" that is just a String will be interpreted as a call to input-text with that String for the target text field.

Examples:

(quick-fill {"#first_name" "Rich"} {"a.foo" click})

quit

(quit)
(quit driver)
Quit the browser completely, including all open windows.

Examples:

(quit)

rectangle

(rectangle q)
(rectangle driver q)
Return a java.awt.Rectangle with the position and dimensions of the first element found with query q (using the location and size functions).

Examples:

(rectangle "div#login") ;=> #<Rectangle java.awt.Rectangle[x=279,y=132,width=403,height=265]>

refresh

(refresh)
(refresh driver)
Refresh the current page in the browser. Note that all references to elements will become "stale" and unusable after a page refresh.

Examples:

(refresh)

select

(select q)
(select driver q)
If the first form element found with query q is not selected, click the element to select it. Otherwise, do nothing and just return the element found.

Examples:

(select "input.already-selected") ;=> do nothing (select "input.not-selected") ;=> click

select-all

(select-all q)
(select-all driver q)
Select all options within the first select list found with query q.

Examples:

(deselect-all "#my-select-list")

select-by-index

(select-by-index q idx)
(select-by-index driver q idx)
Select the option element at index idx (zero-based) within the first select list found with query q.

Examples:

;; ;; Select by index, select 2nd element ;; (select-by-index "#my-select-list" 1)

select-by-text

(select-by-text q text)
(select-by-text driver q text)
Select the option element with visible text text within the first select list found with query q.

Examples:

(select-by-text "#my-select-list" "foo")

select-by-value

(select-by-value q value)
(select-by-value driver q value)
Deselect the option element with value within the first select list found with query q.

Examples:

(deselect-by-value "#my-select-list" "foo")

select-option

(select-option q attr-val)
(select-option driver q attr-val)
Select the option element matching attr-val within the first select list found with query q.

The attr-val can contain :index, :value, or :text keys to find the target option element. Index is the zero-based order of the option element in the list, value is the value of the HTML value attribute, and text is the visible text of the option element on the page.

Examples:

;; ;; By index, select 3rd option element ;; (select-option "#my-select-list" {:index 2})

;; ;; By value of option element ;; (select-option "#my-select-list" {:value "foo"})

;; ;; By visible text of option element ;; (select-option "#my-select-list" {:text "Foo"})

selected-options

(selected-options q)
(selected-options driver q)
Return all selected option elements within the first select list found with query q.

Examples:

(selected-options "#my-select-list")

selected?

(selected? q)
(selected? driver q)
Return true if the first element found with the query q is selected (works for radio buttons, checkboxes, and option tags within select lists).

Examples:

(selected? "input[type='radio'][value='foo']") ;=> true (selected? "option[value='foo']") ;=> false

send-keys

(send-keys q s)
(send-keys driver q s)
Type the string s into the first form element found with query q.

Examples:

(input-text "input#login_field" "semperos")

set-driver!

(set-driver! browser-spec)
(set-driver! browser-spec url)
Set a default Driver for this thread, optionally sending it to a starting url.

Available browsers are :firefox, :chrome, :ie, :opera, :htmlunit and :phantomjs.

Examples:

;; ;; Simple example ;; (set-driver! {:browser :firefox})

;; ;; Full example ;; (set-driver! {:browser :firefox :cache-spec {:strategy :basic, :args [{}], :include [ (fn [element] (= (attribute element :class) "external")) {:css "ol#pages"}]}

;; ;; Use existing Driver record ;; (set-driver! a-driver)

set-finder!

(set-finder! finder-fn)
Set a default finder function, which will be used with all q parameters in functions that require an Element.

Examples:

;; ;; Simple example ;; (set-finder! xpath-finder)

;; ;; Derivative finder function ;; ;; Takes the query string and always prepends "div#container ", which would be ;; useful in situations where you know you're always inside that particular div. ;; (Note that this same functionality is provided by find-element-under, but ;; you get the idea.) ;; (set-finder! (fn [q] (if (element? q) q (css-finder (str "div#container " q)))))

;; ;; Custom finder function ;; ;; If you want to easily switch between using CSS and XPath (e.g., because ;; XPath has the text() function for which no CSS equivalent exists), then ;; you could write something like this, where q would become either the map ;; {:css "query"} or {:xpath "query"} instead of just a string. ;; (set-finder! (fn [q] (if (element? q) q (case (first (keys q)) :css (core/find-elements-by driver (by-css (first (values q)))) :xpath (core/find-elements-by driver (by-xpath (first (values q))))))))

;; ;; (Note: This last example is written to show how to use the lowest-level functions ;; find-elements-by, by-css and by-xpath. The maps {:css "query"} and ;; {:xpath "query"} are themselves acceptable arguments to the find-elements, ;; function, so that function could have been used instead without the case statement.) ;;

submit

(submit q)
(submit driver q)
Submit the form that the first form element found with query q belongs to (this is equivalent to pressing ENTER in a text field while filling out a form).

Examples:

(submit "input#password")

switch-to-active

(switch-to-active)
(switch-to-active driver)
Switch to the page element that currently has focus, or to the body if this cannot be detected.

Examples:

(switch-to-active)

switch-to-default

(switch-to-default)
(switch-to-default driver)
Switch focus to the first first frame of the page, or the main document if the page contains iframes.

Examples:

(switch-to-default)

switch-to-frame

(switch-to-frame frame-q)
(switch-to-frame driver frame-q)
Switch focus to the frame found by the finder query frame-q.

If you need the default behavior of .frame(), you can use clj-webdriver.core/switch-to-frame. For that function, you can pass either a number (the index of the frame on the page), a string (the name or id attribute of the target frame), or an Element of the frame.

Examples:

(switch-to-frame "#target-frame")

switch-to-other-window

(switch-to-other-window)
(switch-to-other-window driver)
If two windows are open, switch focus to the other.

Examples:

(switch-to-other-window)

switch-to-window

(switch-to-window handle)
(switch-to-window driver handle)
Switch focus to the window for the given one of the following:
  • A string representing the target window name (as seen in the application titlebar)
  • A number representing the index (order) of the target window
  • A WindowHandle record

Examples:

;; ;; By name ;; (switch-to-window "Name Of Window")

;; ;; By index (order), open the 3rd window ;; (switch-to-window 2)

;; ;; Passing a WindowHandle record directly (as returned by the window-handle function) ;; (switch-to-window a-window-handle)

tag

(tag q)
(tag driver q)
Return the HTML tag for the first element found with query q.

Examples:

(tag "#foo") ;=> "a"

take-screenshot

(take-screenshot)
(take-screenshot format)
(take-screenshot format destination)
(take-screenshot driver format destination)
Take a screenshot of the browser's current page, optionally specifying the format (:file, :base64, or :bytes) and the destination (something that clojure.java.io/file will accept).

Examples:

;; ;; Simple Example ;; ;; Return screenshot as file object ;; (take-screenshot :file)

;; ;; Specify a default destination for the file object ;; (take-screenshot :file "/path/to/save/screenshot.png")

text

(text q)
(text driver q)
Return the text within the first element found with query q.

Examples:

(text "#message") ;=> "An error occurred."

title

(title)
(title driver)
Return the title of the current page in the browser.

Examples:

(title)

to

(to url)
(to driver url)
Navigate the browser to url.

Examples:

;; ;; Simple Example ;; (to "https://github.com")

;; ;; Custom function for building URL's from a base url ;; (defn go [path] (let [base-url "http://example.com/"] (to (str base-url path)))) ;; (go "test-page") would navigate to "http://example.com/test-page"

toggle

(toggle q)
(toggle driver q)
Toggle is a synonym for click. Click the first element found with query q.

Examples:

(toggle "input[type='checkbox'][value='foo']")

value

(value q)
(value driver q)
Return the value of the HTML value attribute for the first element found with query q. The is identical to (attribute q :value)

Examples:

(value "#my-button") ;=> "submit"

visible?

(visible? q)
(visible? driver q)
Return true if the first element found with query q is visible on the current page in the browser.

Examples:

(visible? "div#container") ;=> true (visible? "a.hidden") ;=> false

wait-until

(wait-until pred)
(wait-until pred timeout)
(wait-until pred timeout interval)
(wait-until driver pred timeout interval)
Make the browser wait until the predicate pred returns true, providing an optional timeout in milliseconds and an optional interval in milliseconds on which to attempt the predicate. If the timeout is exceeded, an exception is thrown.

The predicate is a function that accepts the browser Driver record as its single parameter, and should return a truthy/falsey value.

Examples:

;; ;; Simple example (taken from unit tests) ;; ;; Wait until the title of the page is 'asdf' ;; (execute-script "setTimeout(function () { window.document.title = 'asdf'}, 3000)") (wait-until #(= (title) "asdf"))

;; ;; Wait until an element exists ;; (... code to load page ...) (wait-until #(exists? "#foo")) (click "#foo a.bar")

window-handle

(window-handle)
(window-handle driver)
Return a WindowHandle that contains information about the active window and can be used for switching.

Examples:

(window-handle)

window-handles

(window-handles)
(window-handles driver)
Return WindowHandle records as a seq for all open windows.

Examples:

(window-handles)

with-driver

(with-driver browser-spec & body)
Given a browser-spec to start a browser, execute the forms in body, then call quit on the browser. Uses the default finder function.

Examples:

;; ;; Log into Github ;; (with-driver {:browser :firefox} (to "https://github.com") (click "a[href*='login']")

(input-text "#login_field" "your_username") (-> "#password" (input-text "your_password") submit))

with-driver-fn

(with-driver-fn browser-spec finder-fn & body)
Given a browser-spec to start a browser and a finder-fn to use as a finding function, execute the forms in body, then call quit on the browser.

Examples:

;; ;; Log into Github ;; (with-driver {:browser :firefox} xpath-finder (to "https://github.com") (click "//a[text()='Login']")

(input-text "//input[@id='login_field']" "your_username") (-> "//input[@id='password']" (input-text "your_password") submit))

xpath

(xpath q)
(xpath driver q)
Return an absolute XPath path for the first element found with query q. NOTE: This function relies on executing JavaScript in the browser, and is therefore not as dependable as other functions.

Examples:

(xpath "#login_field") ;=> "/html/body/div[2]/div/div/form/div[2]/label/input"

xpath-finder

(xpath-finder q)
(xpath-finder driver q)
Given a XPath query q, return a lazy seq of the elements found by calling find-elements with by-xpath. If q is an Element, it is returned unchanged.

This function is used internally by the Taxi API as *finder*. See the documentation for set-finder! for examples of extending this function or creating your own custom finder function.

Clone this wiki locally