-
-
Save seryh/f1686aa005e59d4b30acafabd41706c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns selenium.utils | |
(:require [clojure.test :refer :all] | |
[clojure.core.async :refer [timeout buffer alt! alt!! alts!! alts! close! onto-chan go go-loop chan <! >! >!! <!! thread]] | |
[clj-webdriver.taxi :refer :all] | |
[io.aviso.taxi-toolkit.index :refer :all] | |
[clojure.data.json :as json] | |
[io.aviso.taxi-toolkit.url :as url])) | |
(defn ->click! [& args] | |
(apply click args) | |
(first args)) | |
(defn ->sleep! [el timeout] | |
(Thread/sleep timeout) el) | |
(defn type-text | |
([el s] (type-text el s 100)) | |
([el s timeout] | |
(let [size (count s)] | |
(loop [i 0] | |
(let [char (str (get s i))] | |
(when (< i size) | |
(send-keys el char) | |
(Thread/sleep timeout) | |
(recur (inc i)))))) el)) | |
(defn multi-type-text [& body] | |
(let [hash-list (apply hash-map body) | |
doit (fn [coll el s] | |
(let [primise (future (type-text el s) :ok)] | |
(conj coll primise))) | |
promises (reduce-kv doit [] hash-list)] | |
(mapv deref promises))) | |
(defn find-and-select [el text] | |
(click el) | |
(type-text el text) | |
(loop [ajax-active nil] | |
(when (not= ajax-active 0) | |
(recur @(future (execute-script "return iwayjQuery.active"))))) | |
(send-keys el org.openqa.selenium.Keys/ENTER)) | |
#_(-> (find-element {:xpath "//*[@id=\"bookingform\"]/div/div[1]/div/div[2]/div[1]/div[2]/div[2]/input"}) | |
(->click!) | |
(->sleep! 100) | |
(type-text "ленина") | |
(->sleep! 400) | |
(send-keys org.openqa.selenium.Keys/ARROW_DOWN) | |
(->sleep! 800) | |
(send-keys org.openqa.selenium.Keys/ARROW_DOWN) | |
(->sleep! 800) | |
(send-keys org.openqa.selenium.Keys/ENTER) | |
(->sleep! 800) | |
(send-keys org.openqa.selenium.Keys/ARROW_DOWN) | |
(->sleep! 300) | |
(send-keys org.openqa.selenium.Keys/ENTER)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment