Mayvenn / limo

A wrapper around selenium webdriver
Eclipse Public License 1.0
25 stars 4 forks source link

best way to get cookies #9

Open bhougland18 opened 4 years ago

bhougland18 commented 4 years ago

What would be the best way to get the cookies from selenium driver?

sheelc commented 4 years ago

Here are some helper functions we use to pull cookies out from the driver (and transform them to a Clojure map).

(defn ^:private cookie->map [^org.openqa.selenium.Cookie cookie]
  {:secure?    (.isSecure cookie)
   :http-only? (.isHttpOnly cookie)
   :domain     (.getDomain cookie)
   :expiry     (.getExpiry cookie)
   :name       (.getName cookie)
   :path       (.getPath cookie)
   :value      (.getValue cookie)})

(defn get-cookie
  ([key] (get-cookie limo.api/*driver* key))
  ([driver key] (cookie->map (.. driver manage (getCookieNamed key)))))

(defn all-cookies
  ([] (all-cookies limo.api/*driver*))
  ([driver] (map cookie->map (seq (.. driver manage getCookies)))))

If these are useful, perhaps we should add them to limo @jeffh / @bhougland18 ?

bhougland18 commented 4 years ago

@sheelc

Thank you for this information! I think this would be useful because it looks like you can only delete cookies at the moment.

jeffh commented 4 years ago

Yeah, I’d think it would be useful to add. We should probably port that helper code we have internally into limo.