 (defn fill-form-el [el-form form]
   (doseq [[field value] form]
     (let [term (format "//input[@name='%s']" (name field))]
-      (with-el-from el-form term el-input
-        (fill-el el-input (str value))))))
+      (with-xpath
+        (with-el-from el-form term el-input
+          (fill-el el-input (str value)))))))
 
 (defn fill-form [term form]
   (with-el term el-form
     (fill-form-el el-form form)))
+
+(defn submit-form-el [el-form form]
+  (fill-form-el el-form form)
+  (with-xpath
+    (with-el-from el-form "//submit | //button[@type='submit']" el-submit
+      (click-el el-submit))))
+
+(defn submit-form [term form]
+  (with-el term el-form
+    (submit-form-el el-form form)))
+
+(defn clear-form-el [el-form]
+  (with-xpath
+    (with-els-from el-form "//input[not(@type='hidden')]" el-input
+      (clear-el el-input))))
+
+(defn clear-form [term]
+  (with-el term el-form
+    (clear-form-el el-form)))
 
 (defn get-form-el [el-form]
   (let [term "//input"

       ~@body)))

;;
;; element properties
;;

(defn prop-el [el name]
  (api/get-element-property *server* *session* el name))

(defn prop [term name]
  (with-el term el
    (prop-el el name)))

(defmacro with-prop-el [el name & body]
  `(let [~name (prop-el ~el ~(str name))]
     ~@body))

(defmacro with-prop [term name & body]
  `(with-el ~term el#
     (with-prop-el el# ~name
       ~@body)))

(defmacro with-props-el [el names & body]
  (let [func (fn [name] `(prop-el ~el ~(str name)))
        forms (map func names)
        binds (-> names
                  (interleave forms)
                  vec
                  vector)]
    `(let ~@binds
       ~@body)))

(defmacro with-props [term names & body]
  `(with-el ~term el#
     (with-props-el el# ~names
       ~@body)))

;;
;; tests
;;

(deftest simple-test
  (let [host "127.0.0.1"
        port (random-port) ;; 4444 ;; 8910
        args ["geckodriver" "--host" host "--port" port]
        capabilities {}
        html "<input class=\"input__control input__input\" tabindex=\"2\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" aria-autocomplete=\"list\" aria-label=\"Запрос\" id=\"text\" maxlength=\"400\" name=\"text\">"
        input "//input[@id='text']"]

    ;; with-start host port
    (proc/with-proc p [args]
      (with-server host port
        (wait-running)
        (with-session capabilities
          (client/with-pool {}
            (go-url "http://ya.ru")
            (js-set-hash "fooooo")
            ;; (with-url url
            ;;   (is (= url 1)))

                (is (= height 46.0)))))
          (screenshot "page.png")
          (screenshot input "element.png")
          (clear-form "//form")
          ;; (submit-form "//form" {:text "sdfsdfsdfsdfs"})
          ;; (wait 5)
          )))))
