From c72a7840adbe01bca69f40914764dff7f75d42a4 Mon Sep 17 00:00:00 2001 From: "Alex.Shi" Date: Wed, 22 Jul 2020 18:45:11 +0300 Subject: [PATCH] add select fn (#241) * add select fn --- resources/html/test.html | 6 ++++++ src/etaoin/api.clj | 14 ++++++++++++++ test/etaoin/api_test.clj | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/resources/html/test.html b/resources/html/test.html index 4a3f86d4..2c1fbcc7 100644 --- a/resources/html/test.html +++ b/resources/html/test.html @@ -36,6 +36,12 @@

Input section


+
diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index 800abd50..3219c878 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -2438,6 +2438,20 @@ [driver q text] (fill-human-el driver (query driver q) text)) +(defn select + "Select element in select-box by visible text on click. + + Arguments: + + - `driver`: a driver instance, + + - `q`: a query term, see `query` function for more info, + + - `text`: a string to input." + [driver q text] + (let [el (query driver q {:tag :option :fn/has-text text})] + (click-el driver el))) + (defn clear-el "Clears an element by its identifier." [driver el] diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 34f8f33a..956629fc 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -73,6 +73,14 @@ (-> (invisible? {:id :div-hidden}) is) (-> (invisible? {:id :dunno-foo-bar}) is))) +(deftest test-select + (testing "test `select` on select-box" + (let [default-val (get-element-value *driver* :simple-country) + _ (select *driver* :simple-country "France") + selected-val (get-element-value *driver* :simple-country)] + (is (= "rf" default-val)) + (is (= "fr" selected-val))))) + (deftest test-input (testing "fill multiple imputs" (doto *driver*