semperos/clj-webdriver — Issue #35: Proposal on quick-fill
Author: locopati
Created: 2012-02-03 21:30:02+00:00
State: open

I started playing around with a form-filler before I noticed quick-fill in the docs. Though very flexible, quick-fill requires more boilerplate around your key/values (and I wasn't quite sure how to make select-by-index work). Wanted to throw this out there for thoughts on a simpler variant to quickfill (of course, the rest of the widget set would need to be filled out).

```clojure
(defmulti set-widget which-widget)
(defmethod set-widget ["select" "select-one"] [ele val]
(select-by-index ele val))
(defmethod set-widget ["input" "radio"] [ele val]
(click ele))

(defn set-form
"Given a map of CSS lookup strings to values, apply the values to each element specified by the lookup. Pass nil for elements like radio-buttons and checkboxes that don't take a value."
[driver widget-values]
(map #(set-widget (find-it driver {:css (key %)}) (val %)) widget-values))

;; example
(set-form driver {"#a-div input[value=M]" nil, "#my-sel-1" 1, "#my-sel-2" 1, "#my-sel-3" 1})
```