sparkledriver.element

attr

(attr element attribute)

Return the value of attribute for element

clear-text!

(clear-text! element)

Clear the current text of text-entry element. Used with send-text! to manipulate form fields.

click!

(click! element)

Send a browser click event to element.

click-all!

(click-all! elements)

Click every element in the sequence elements. Returns the number of elements clicked.

css-value

(css-value element property)

Return the value of CSS property for element

displayed?

(displayed? element)

Is this element displayed or not? This method avoids the problem of having to parse an element’s CSS.

enabled?

(enabled? element)

Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

find-by-class

(find-by-class browser-or-elem class)

Return the first element with class name class that’s a child of browser-or-elem (which can be a browser or element). Throws an exception if there’s no such element! If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-class*

(find-by-class* browser-or-elem class)

Return all elements with class name class that are children of browser-or-elem (which can be a browser or element) or an empty sequence. If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-css

(find-by-css browser-or-elem css-selector)

Return the first element that matches css-selector, starting from browser-or-elem (which can be a browser or element). Throws an exception if there’s no such element! If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-css*

(find-by-css* browser-or-elem css-selector)

Return all elements that match css-selector, starting from browser-or-elem (which can be a browser or element) or an empty sequence. If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-id

(find-by-id browser-or-elem id)

Return the single element with id that’s a child of browser-or-elem (which can be a browser or element). Throws an exception if there’s no such element! If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-tag

(find-by-tag browser-or-elem tag)

Return the first element with tag name tag that’s a child of browser-or-elem (which can be a browser or element). Throws an exception if there’s no such element! If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-tag*

(find-by-tag* browser-or-elem tag)

Return all elements with tag name tag that are children of browser-or-elem (which can be a browser or element) or an empty sequence. If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

find-by-xpath

(find-by-xpath browser-or-elem xpath)

Return the first element that matches xpath, starting from browser-or-elem (which can be a browser or element). Throws an exception if there’s no such element! If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

For example:

(with-browser [browser (make-browser)]
  (-> (fetch! browser "http://clojure.org")
      (find-by-xpath* "//div[@class='clj-intro-message']/p")
      (nth 2)
      text))
;;=> "I hope you find Clojure's combination of facilities elegant, powerful, practical and fun to use."

find-by-xpath*

(find-by-xpath* browser-or-elem xpath)

Return all elements that match xpath, starting from browser-or-elem (which can be a browser or element) or an empty sequence. If called with retry-fn bound - for example by using the with-retry macro - will wrap the operation in that function.

id

(id element)

Return the value of the id attribute of element

inner-html

(inner-html element)

Return the innerHTML of element

location

(location element)

Location on the page of the top left-hand corner of the rendered element.

outer-html

(outer-html element)

Return the outerHTML of element

rectangle

(rectangle element)

The location and size of the rendered element.

screenshot

(screenshot browser)

Takes a screenshot of browser’s current state and stores the image in a temporary file, then returns the file’s absolute path.

(N.B. this function is in the element namespace because it should take a browser or an element, but there’s presently an upstream bug preventing this from working.)

selected?

(selected? element)

Return whether or not this element is selected

send-text!

(send-text! element text)

Send the string text to element, as if the user typed it.

size

(size element)

What is the width and height of the rendered element?

submit-form!

(submit-form! element)

Submit element, which should be an HTML form.

tag

(tag element)

Return the tag name of element

text

(text element)

Return the complete visible textual content of element (including any children). Text from hidden elements is not included.