Skip to content

Commit

Permalink
116 initial code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
igrishaev committed Feb 26, 2018
1 parent 5902255 commit 51cc935
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/etaoin/api.clj
Expand Up @@ -1670,30 +1670,21 @@
(def disabled? (complement enabled?))

(defn has-text?
"Returns true if text appears anywhere on a page.
When a query expression is passed, tries to find that text
into the first element found with that term."
"Returns true if a passed text appears anywhere on a page.
With a leading query expression, finds a text inside the first
element that matches the query."
([driver text]
(has-text? driver {:tag :*} text))
(with-http-error
(boolean
(query driver {:xpath (xpath/node-by-text text)}))))

([driver q text]
(let [[loc term] (query/expand driver q)
term1 (format "%s[contains(text(), \"%s\")]" term text) ;; todo refactor here
term2 (format "%s//*[contains(text(), \"%s\")]" term text)] ;; and here
(when-not (= loc locator-xpath)
(throw+ {:type :etaoin/locator
:driver @driver
:message "Only XPath locator works here."
:text text
:q q}))
(or
(with-http-error
(find-element* driver loc term1)
true)
(with-http-error
(find-element* driver loc term2)
true)
false))))
(let [x {:xpath (xpath/node-by-text text)}]
(with-http-error
(boolean
(if (vector? q)
(apply query driver (conj q x))
(query driver q x)))))))

(defn has-class-el?
[driver el class]
Expand Down
4 changes: 4 additions & 0 deletions src/etaoin/xpath.clj
Expand Up @@ -4,6 +4,10 @@

(def Q \")

(defn node-by-text
[text]
(format ".//text()[contains(., %s%s%s)]/.." Q text Q))

(defmulti to-str type)

(defmethod to-str clojure.lang.Keyword
Expand Down

0 comments on commit 51cc935

Please sign in to comment.