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

Composite Actions

semperos edited this page Feb 18, 2012 · 4 revisions

As part of an effort to support more complex user interactions, Selenium-WebDriver has added an Actions class that handles things like drag-and-drop functionality (see this page on their wiki).

Clj-webdriver provides equivalent Clojure functions for individual methods in that class, as well as two macros to help build composite actions and execute them. See the following two examples:

;; Compose several advanced actions and immediately perform them on the page
(->actions b
  (click-and-hold (find-element b {:id "draggable"}))
  (move-to-element (find-element b {:id "droppable"}))
  (release (find-element b {:id "droppable"})))

;; Build a composite action and perform it later
(def my-comp-act (->build-composite-action b
                   (click-and-hold (find-element b {:id "draggable"}))
                   (move-to-element (find-element b {:id "droppable"}))
                   (release (find-element b {:id "droppable"}))))

(perform my-comp-act)

The following actions are exposed for use with Driver instances:

  • click-and-hold
  • double-click
  • drag-and-drop
  • drag-and-drop-by
  • key-down
  • key-up
  • move-by-offset
  • move-to-element
  • release

Use these when you only need to use one (e.g., you only need to execute a double-click, or a drag-and-drop).

If you need to compose actions as seen in the above examples, note that clj-webdriver has extended org.openqa.selenium.interactions.Actions and Action of the same package. This allows the two macros ->actions and ->build-composite-actions to encapsulate the use of Java objects, while making it easy to string together these advanced actions.

Note that only the above functions are supported with composite actions, due to Selenium-WebDriver's API. Also note that the ->actions and ->build-composite-actions macros are threading macros, so you do not need to pass in a driver instance to the functions in the body of each macro.

Clone this wiki locally