forked from babashka/pod-babashka-etaoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.clj
40 lines (30 loc) · 1.27 KB
/
example.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(require '[babashka.pods :as pods])
#_(pods/load-pod ["lein" "run" "-m" "pod.babashka.etaoin"])
(pods/load-pod "./pod-babashka-etaoin")
(require '[pod.babashka.etaoin :as eta]
'[pod.babashka.etaoin.keys :as k])
#_(def driver (eta/firefox)) ;; here, a Firefox window should appear
#_(def driver (eta/chrome))
(def driver (eta/firefox-headless))
;; let's perform a quick Wiki session
(eta/go driver "https://en.wikipedia.org/")
(eta/wait-visible driver [{:id :simpleSearch} {:tag :input :name :search}])
;; search for something
(eta/fill driver {:tag :input :name :search} "Clojure programming language")
(eta/fill driver {:tag :input :name :search} k/enter)
(eta/wait-visible driver {:class :mw-search-results})
;; I'm sure the first link is what I was looking for
(eta/click driver [{:class :mw-search-results} {:class :mw-search-result-heading} {:tag :a}])
(eta/wait-visible driver {:id :firstHeading})
;; let's ensure
(prn (eta/get-url driver)) ;; "https://en.wikipedia.org/wiki/Clojure"
(prn (eta/get-title driver)) ;; "Clojure - Wikipedia"
(prn (eta/has-text? driver "Clojure")) ;; true
;; navigate on history
(eta/back driver)
(eta/forward driver)
(eta/refresh driver)
(prn (eta/get-title driver)) ;; "Clojure - Wikipedia"
;; stops Firefox and HTTP server
(eta/quit driver)
nil