 (defn bounding-box
   ([node] (bounding-box @current-automation node))
   ([{c :connection :as ctx} node]
-   (let [{:keys [width height content]} (:model (dom/get-box-model c node))
+   (let [node (to-node-ref ctx node)
+         {:keys [width height content]} (:model (dom/get-box-model c node))
          [x y] content]
      {:x x :y y
       :width width :height height

  ([node attribute-name attribute-value]
   (set-attribute @current-automation node attribute-name attribute-value))
  ([{c :connection :as ctx} node attribute-name attribute-value]
   (dom/set-attribute-value c (merge node {:name attribute-name
                                           :value attribute-value}))))

(defn click
  ([node] (click @current-automation node))
  ([{c :connection :as ctx} node]
   (let [node (to-node-ref ctx node)]
     (visible ctx node)
     (let [{:keys [x y]} (scroll-into-view ctx node)
           event {:x x :y y :button "left" :click-count 1}]
       (input/dispatch-mouse-event c (assoc event :type "mousePressed"))
       (input/dispatch-mouse-event c (assoc event :type "mouseReleased"))

       ;; FIXME: Artificial slowdown, nodes that appear after clicking may be found
       ;; by a selector, but cannot be resolved (aren't sent to us by chrome yet?).
       ;; Implement a "dom" model that has all the nodes and keep resolved nodes
       ;; in the implementation. Always resolve a node from the "dom"
       (Thread/sleep 100)))))

(defn click-navigate
  "Click element and wait for navigation to be done."
