-
Notifications
You must be signed in to change notification settings - Fork 93
Taxi API Documentation
- add-cookie
- attribute
- back
- clear
- click
- close
- cookie
- cookies
- css-finder
- current-url
- delete-all-cookies
- delete-cookie
- deselect
- deselect-all
- deselect-by-index
- deselect-by-text
- deselect-by-value
- deselect-option
- displayed?
- drag-and-drop
- drag-and-drop-by
- element
- elements
- element-size
- enabled?
- execute-script
- exists?
- find-element
- find-element-under
- find-elements
- find-elements-under
- find-table-cell
- find-table-row
- find-window
- find-windows
- flash
- focus
- forward
- get-url
- html
- implicit-wait
- input-text
- intersect?
- location
- location-once-visible
- multiple?
- options
- other-windows
- page-source
- present?
- quick-fill
- quick-fill-submit
- quit
- rectangle
- refresh
- select
- select-all
- select-by-index
- select-by-text
- select-by-value
- select-option
- selected-options
- selected?
- send-keys
- set-driver!
- set-finder!
- submit
- switch-to-active
- switch-to-default
- switch-to-frame
- switch-to-other-window
- switch-to-window
- tag
- take-screenshot
- text
- title
- to
- toggle
- value
- visible?
- wait-until
- window-handle
- window-handles
- with-driver
- with-driver-fn
- xpath
- xpath-finder
(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).;; ;; 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 q attr)
(attribute driver q attr)
For the first element found with queryq
, return the value of the givenattribute
.;; ;; 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 n)
(back driver n)
Navigate back in the browser history, optionallyn
times.;; ;; Simple Example ;; (back)
;; ;; Specify number of times to go back ;; (back 2)
(clear q)
(clear driver q)
Clear the contents (the HTML value attribute) of the first form element found with queryq
.(clear "input.with-default-text")
(click q)
(click driver q)
Click the first element found with queryq
.(click "a#foo")
(close)
(close driver)
Close the browser. If multiple windows are open, this only closes the active window.(close)
(cookie cookie-name)
(cookie driver cookie-name)
Return the cookie with namecookie-name
. Returns aCookie
record which contains a:cookie
field with the original Java object.(cookie "foo")
(cookies)
(cookies driver)
Return a seq of all cookies in the browser session. Items areCookie
records, which themselves contain a:cookie
field with the original Java objects.(cookies)
(css-finder q)
(css-finder driver q)
Given a CSS queryq
, return a lazy seq of the elements found by callingfind-elements
withby-css
. Ifq
is anElement
, it is returned unchanged.This function is used internally by the Taxi API as
*finder*
. See the documentation forset-finder!
for examples of extending this function or creating your own custom finder function.
(current-url)
(current-url driver)
Return the current url of the browser.(current-url)
(delete-all-cookies)
(delete-all-cookies driver)
Delete all cookies from the browser session.(delete-all-cookies)
(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.;; ;; By name ;; (delete-cookie "foo")
;; ;; With
Cookie
record as returned bycookies
orcookie
functions ;; (delete-cookie a-cookie)
(deselect q)
(deselect driver q)
If the first form element found with queryq
is selected, click the element to deselect it. Otherwise, do nothing and just return the element found.(deselect "input.already-selected") ;=> click (deselect "input.not-selected") ;=> do nothing
(deselect-all q)
(deselect-all driver q)
Deselect all options within the first select list found with queryq
.(deselect-all "#my-select-list")
(deselect-by-index q idx)
(deselect-by-index driver q idx)
Deselect the option element at indexidx
(zero-based) within the first select list found with queryq
.;; ;; Deselect by index, deselect 2nd element ;; (deselect-by-index "#my-select-list" 1)
(deselect-by-text q text)
(deselect-by-text driver q text)
Deselect the option element with visible texttext
within the first select list found with queryq
.(deselect-by-text "#my-select-list" "Foo")
(deselect-by-value q value)
(deselect-by-value driver q value)
Deselect the option element withvalue
within the first select list found with queryq
.(deselect-by-value "#my-select-list" "foo")
(deselect-option q attr-val)
(deselect-option driver q attr-val)
Deselect the option element matchingattr-val
within the first select list found with queryq
.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.;; ;; 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? q)
(displayed? driver q)
Return true if the first element found with queryq
is visible on the page.(displayed? "div#container") ;=> true (displayed? "a.hidden") ;=> false
(drag-and-drop qa qb)
(drag-and-drop driver qa qb)
Drag the first element found with queryqa
onto the first element found with queryqb
.;; ;; Drag div with id "draggable" onto div with id "droppable" ;; (drag-and-drop "#draggable" "#droppable")
(drag-and-drop-by q x-y-map)
(drag-and-drop-by driver q x-y-map)
Drag the first element found with queryq
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.;; ;; 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 q)
(element driver q)
Given a queryq
, return the first element that the default finder function returns.;; ;; 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 q)
(elements driver q)
Given a queryq
, return the elements that the default finder function returns.;; ;; Simple Example ;; ;; Save a seq of anchor tags (links) for later. ;; (def target-elements (elements "a"))
(element-size q)
(element-size driver q)
Return the size of the first element found with queryq
in pixels as a map of:width
and:height
..(element-size "div#container") ;=> {:width 960, :height 2000}
(enabled? q)
(enabled? driver q)
Return true if the first form element found with queryq
is enabled (not disabled).(enabled? "input") ;=> true (enabled? "input[disabled='disabled']") ;=> false
(execute-script js & js-args)
Execute the JavaScript codejs
with argumentsjs-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.
;; ;; 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? q)
(exists? driver q)
Return true if the first element found with queryq
exists on the current page in the browser.(exists? "a#foo") ;=> true (exists? "footer") ;=> false
(find-element attr-val)
(find-element driver attr-val)
Return firstElement
record that matches the givenattr-val
. Prefer the default behavior ofelement
when possible.Whereas the
element
function uses a queryq
with the default finder function, this function requires anattr-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)
;; ;; 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 q-parent attr-val)
Find the first element that is a child of the element found with queryq-parent
, using the givenattr-val
. Ifq-parent
is anElement
, it will be used as-is. Theattr-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 fullattr-val
map instead of aby-clause
, which will be implemented pending a re-write offind-elements
.;; ;; 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 attr-val)
(find-elements driver attr-val)
ReturnElement
records that match the givenattr-val
. Prefer the default behavior ofelements
when possible.Whereas the
elements
function uses a queryq
with the default finder function, this function requires anattr-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)
;; ;; 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 q-parent attr-val)
Find the elements that are children of the element found with queryq-parent
, using the givenattr-val
. Ifq-parent
is anElement
, it will be used as-is. Theattr-val
can either be a find-element-style map of attributes and values, or a by-clause (by-tag
,by-class
, etc.);; ;; 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 table-q coords)
(find-table-cell driver table-q coords)
Within the table found with querytable-q
, return the table cell at coordinatescoords
. The top-left cell has coordinates[0 0]
.;; ;; Simple example, find 2nd cell on 2nd row from top ;; (find-table-cell "table#my-table" [1 1])
(find-table-row table-q row)
(find-table-row driver table-q row)
Within the table found with querytable-q
, return a seq of all cells at row numberrow
. The top-most row is row0
(zero-based index).;; ;; Simple example, return cells in second row ;; (find-table-row "table#my-table" 1)
(find-window attr-val)
(find-window driver attr-val)
Return the firstWindowHandle
record that matches the givenattr-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.;; ;; 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 attr-val)
(find-windows driver attr-val)
Return allWindowHandle
records that match the givenattr-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.;; ;; By name ;; (find-windows {:title "Window Title"})
;; ;; By URL ;; (find-windows {:url "http://example.com/test-page"})
;; ;; By index ;; (find-windows {:index 2})
(flash q)
(flash driver q)
Flash the background color of the first element found with queryq
.(flash "a.hard-to-see")
(focus q)
(focus driver q)
Explicitly give the first element found with queryq
focus on the page.(focus "input.next-element")
(forward)
(forward n)
(forward driver n)
Navigate forward in the browser history.;; ;; Simple Example ;; (forward)
;; ;; Specify number of times to go back ;; (forward 2)
(get-url url)
(get-url driver url)
Navigate the browser tourl
.;; ;; 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 q)
(html driver q)
Return the inner html of the first element found with queryq
.(html "div.with-interesting-html")
(implicit-wait timeout)
(implicit-wait driver timeout)
Set the globaltimeout
that the browser should wait when attempting to find elements on the page, before timing out with an exception.;; ;; 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 q s)
(input-text driver q s)
Type the strings
into the first form element found with queryq
.(input-text "input#login_field" "semperos")
(intersect? qa qb)
(intersect? driver qa qb)
Return true if the first element found with queryqa
intersects with the first element found with queryqb
.(intersect? "#login" "#login_field") ;=> true (intersect? "#login_field" "#password") ;=> false
(location q)
(location driver q)
Return a map of:x
and:y
coordinates for the first element found with queryq
.(location "a#foo") ;=> {:x 240, :y 300}
(location-once-visible q)
(location-once-visible driver q)
Return a map of:x
and:y
coordinates for the first element found with queryq
once the page has been scrolled enough to be visible in the viewport.(location-once-visible "a#foo") ;=> {:x 240, :y 300}
(multiple? q)
(multiple? driver q)
Return true if the first select list found with queryq
allows multiple selections.(multiple? "select.multiple") ;=> true (multiple? "select.not-multiple") ;=> false
(options q)
(options driver q)
Return all option elements within the first select list found with queryq
.(options "#my-select-list")
(other-windows)
(other-windows driver)
Return aWindow
for all open windows except the active one.(other-windows)
(page-source)
(page-source driver)
Return the source code of the current page in the browser.;; ;; 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? q)
(present? driver q)
Return true if the first element found with queryq
both exists and is visible on the page.(present? "div#container") ;=> true (present? "a#skip-to-navigation") ;=> false
(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 thedistinct
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.(quick-fill {"#first_name" "Rich"} {"a.foo" click})
(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.(quick-fill {"#first_name" "Rich"} {"a.foo" click})
(rectangle q)
(rectangle driver q)
Return ajava.awt.Rectangle
with the position and dimensions of the first element found with queryq
(using thelocation
andsize
functions).(rectangle "div#login") ;=> #<Rectangle java.awt.Rectangle[x=279,y=132,width=403,height=265]>
(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.(refresh)
(select q)
(select driver q)
If the first form element found with queryq
is not selected, click the element to select it. Otherwise, do nothing and just return the element found.(select "input.already-selected") ;=> do nothing (select "input.not-selected") ;=> click
(select-all q)
(select-all driver q)
Select all options within the first select list found with queryq
.(deselect-all "#my-select-list")
(select-by-index q idx)
(select-by-index driver q idx)
Select the option element at indexidx
(zero-based) within the first select list found with queryq
.;; ;; Select by index, select 2nd element ;; (select-by-index "#my-select-list" 1)
(select-by-text q text)
(select-by-text driver q text)
Select the option element with visible texttext
within the first select list found with queryq
.(select-by-text "#my-select-list" "foo")
(select-by-value q value)
(select-by-value driver q value)
Deselect the option element withvalue
within the first select list found with queryq
.(deselect-by-value "#my-select-list" "foo")
(select-option q attr-val)
(select-option driver q attr-val)
Select the option element matchingattr-val
within the first select list found with queryq
.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.;; ;; 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 q)
(selected-options driver q)
Return all selected option elements within the first select list found with queryq
.(selected-options "#my-select-list")
(selected? q)
(selected? driver q)
Return true if the first element found with the queryq
is selected (works for radio buttons, checkboxes, and option tags within select lists).(selected? "input[type='radio'][value='foo']") ;=> true (selected? "option[value='foo']") ;=> false
(send-keys q s)
(send-keys driver q s)
Type the strings
into the first form element found with queryq
.(input-text "input#login_field" "semperos")
(set-driver! browser-spec)
(set-driver! browser-spec url)
Set a defaultDriver
for this thread, optionally sending it to a startingurl
.Available browsers are
:firefox
,:chrome
,:ie
,:opera
,:htmlunit
and:phantomjs
.;; ;; 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! finder-fn)
Set a default finder function, which will be used with allq
parameters in functions that require an Element.;; ;; 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
andby-xpath
. The maps{:css "query"}
and ;;{:xpath "query"}
are themselves acceptable arguments to thefind-elements
, ;; function, so that function could have been used instead without thecase
statement.) ;;
(submit q)
(submit driver q)
Submit the form that the first form element found with queryq
belongs to (this is equivalent to pressing ENTER in a text field while filling out a form).(submit "input#password")
(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.(switch-to-active)
(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.(switch-to-default)
(switch-to-frame frame-q)
(switch-to-frame driver frame-q)
Switch focus to the frame found by the finder queryframe-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 (thename
orid
attribute of the target frame), or anElement
of the frame.(switch-to-frame "#target-frame")
(switch-to-other-window)
(switch-to-other-window driver)
If two windows are open, switch focus to the other.(switch-to-other-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
;; ;; 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 q)
(tag driver q)
Return the HTML tag for the first element found with queryq
.(tag "#foo") ;=> "a"
(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 thedestination
(something thatclojure.java.io/file
will accept).;; ;; 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 q)
(text driver q)
Return the text within the first element found with queryq
.(text "#message") ;=> "An error occurred."
(to url)
(to driver url)
Navigate the browser tourl
.;; ;; 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 q)
(toggle driver q)
Toggle is a synonym for click. Click the first element found with queryq
.(toggle "input[type='checkbox'][value='foo']")
(value q)
(value driver q)
Return the value of the HTML value attribute for the first element found with queryq
. The is identical to(attribute q :value)
(value "#my-button") ;=> "submit"
(visible? q)
(visible? driver q)
Return true if the first element found with queryq
is visible on the current page in the browser.(visible? "div#container") ;=> true (visible? "a.hidden") ;=> false
(wait-until pred)
(wait-until pred timeout)
(wait-until pred timeout interval)
(wait-until driver pred timeout interval)
Make the browser wait until the predicatepred
returns true, providing an optionaltimeout
in milliseconds and an optionalinterval
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.;; ;; 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 driver)
Return aWindowHandle
that contains information about the active window and can be used for switching.(window-handle)
(window-handles)
(window-handles driver)
ReturnWindowHandle
records as a seq for all open windows.(window-handles)
(with-driver browser-spec & body)
Given abrowser-spec
to start a browser, execute the forms inbody
, then callquit
on the browser. Uses the default finder function.;; ;; 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 browser-spec finder-fn & body)
Given abrowser-spec
to start a browser and afinder-fn
to use as a finding function, execute the forms inbody
, then callquit
on the browser.;; ;; 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 q)
(xpath driver q)
Return an absolute XPath path for the first element found with queryq
. NOTE: This function relies on executing JavaScript in the browser, and is therefore not as dependable as other functions.(xpath "#login_field") ;=> "/html/body/div[2]/div/div/form/div[2]/label/input"
(xpath-finder q)
(xpath-finder driver q)
Given a XPath queryq
, return a lazy seq of the elements found by callingfind-elements
withby-xpath
. Ifq
is anElement
, it is returned unchanged.This function is used internally by the Taxi API as
*finder*
. See the documentation forset-finder!
for examples of extending this function or creating your own custom finder function.
The clj-webdriver Wiki by Daniel Gregoire and community is licensed under a Creative Commons Attribution 4.0 International License. Based on a work at https://github.com/semperos/clj-webdriver/wiki.