Skip to content

Element API

semperos edited this page Apr 30, 2013 · 7 revisions

Once you've positioned your browser driver at the page you want and have setup any other parameters (like caching, grid support, or a special Firefox profile), you are ready to interact with individual elements on the page.

Finding Things

The heart of clj-webdriver's API is the find-element function. This function wraps the various ways that Selenium-WebDriver allows you to find elements and condenses them into a handful of "mini languages" for finding elements on the page, hopefully in a more Clojure-amenable fashion.

This section of the wiki is underdeveloped. Track progress on improving it and find more examples of find-element in Issue #100.

Element Actions

Once you've used find-element to locate an element of interest, you can perform any number of actions on the element:

Element Information:

  • attribute - Return the given attribute of the given page element
  • displayed?, visible?, present? - Synonyms for the same function, which returns true or false depending on whether or not the given element is visible on the page
  • exists? - Return true if the given element exists (new signature in version 0.5.x)
  • html - Return the outer HTML of the given page element
  • location - Return the X/Y coordinates of the given page element within the view port
  • location-once-visible - Return the same as location, but only when the given element is made visible by scrolling down the page
  • tag - Return the tag of the given element
  • text - Return the textual content of the given page element
  • value - A shortcut for (attribute element :value)
  • xpath - Return the XPath expression which points to the given page element

Here are information-based functions that are specific to form elements:

  • enabled? - Return true or false depending on whether or not the given element is enabled
  • selected? - Return true or false depending on whether or not the given element is selected

Element Actions:

(Many of these functions are limited specifically to form elements)

  • clear - Clear the contents of the given element (e.g. text field)
  • click - Click the given page element
  • deselect - Deselect the given option element (multi-select select field)
  • drag-and-drop-by - Drag an element by given horizontal and vertical pixel dimensions
  • drag-and-drop-on - Drag one element onto another
  • flash - Visibly flash the given element (helpful for spotting hard-to-see elements on the page during test composition)
  • focus - Shift focus to the given page element
  • select - Select the given option element
  • send-keys, input-text - Send the given string to the given page element (e.g. text field)
  • submit - Submit the form that contains the given page element

Caching Things

Read the page on Caching Support for more information about caching elements of the page.

Something went wrong with that request. Please try again.