Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes issue #19. Make find-it/find-them return nil when supplied an e…

…mpty map as attr-val
  • Loading branch information...
commit 14b5d8a3fb52739953eb8789b0f746e8299d514e 1 parent 071e3ff
@semperos semperos authored
Showing with 22 additions and 19 deletions.
  1. +22 −19 src/clj_webdriver/core_driver.clj
View
41 src/clj_webdriver/core_driver.clj
@@ -250,25 +250,28 @@
;; NoSuchElementException caught so that `exists?` will behave as expected
(find-them
([driver attr-val]
- (try
- (cond
- (= attr-val :button*) (find-them driver :button* nil)
- (keyword? attr-val) (find-elements
- driver
- (by-tag-name (name attr-val))) ; supplied just :tag
- (vector? attr-val) (cond
- (some #{:row :col} attr-val) (find-table-cells driver attr-val)
- (query-with-ancestry-has-regex? attr-val) (if (query-with-ancestry-has-regex? (drop-last 2 attr-val))
- (throw (IllegalArgumentException.
- (str "You may not pass in a regex until "
- "the last attribute-value pair")))
- (filter-elements-by-regex
- (find-elements driver (by-xpath (str (build-xpath-with-ancestry attr-val) "//*")))
- (last attr-val)))
- :else (find-elements driver (by-xpath (build-xpath-with-ancestry attr-val)))) ; supplied vector of queries in hierarchy
- (map? attr-val) (find-them driver :* attr-val))
- (catch org.openqa.selenium.NoSuchElementException e
- (lazy-seq (init-element nil)))))
+ (if (and (map? attr-val)
+ (empty? attr-val))
+ nil
+ (try
+ (cond
+ (= attr-val :button*) (find-them driver :button* nil)
+ (keyword? attr-val) (find-elements
+ driver
+ (by-tag-name (name attr-val))) ; supplied just :tag
+ (vector? attr-val) (cond
+ (some #{:row :col} attr-val) (find-table-cells driver attr-val)
+ (query-with-ancestry-has-regex? attr-val) (if (query-with-ancestry-has-regex? (drop-last 2 attr-val))
+ (throw (IllegalArgumentException.
+ (str "You may not pass in a regex until "
+ "the last attribute-value pair")))
+ (filter-elements-by-regex
+ (find-elements driver (by-xpath (str (build-xpath-with-ancestry attr-val) "//*")))
+ (last attr-val)))
+ :else (find-elements driver (by-xpath (build-xpath-with-ancestry attr-val)))) ; supplied vector of queries in hierarchy
+ (map? attr-val) (find-them driver :* attr-val))
+ (catch org.openqa.selenium.NoSuchElementException e
+ (lazy-seq (init-element nil))))))
([driver tag attr-val]
(when (keyword? driver) ; I keep forgetting to pass in the WebDriver instance while testing
(throw (IllegalArgumentException.
Please sign in to comment.
Something went wrong with that request. Please try again.