etaoin

fabrao 2023-03-28T19:07:05.111219Z

Hello all, I'm thinking how to query this element:

fabrao 2023-03-28T19:07:14.119399Z

<span>
GMT(+00:00)
Universal
</span>

fabrao 2023-03-28T19:08:29.455089Z

.//span[text()[2],'Universal'] ?

fabrao 2023-03-30T17:43:11.174789Z

@lee it's failing if you have something before like this options Etc/GMT and GMT. I had to read the parent element to get it work, not directly to that element. The code was something like this:

(defn select-element-from-options [option]
  (->>
    (eapi/query-tree *driver* {:data-ci "timezone-id-autocomplete-input"} {:tag :ul} {:tag :li} {:tag :a})
    (filter #(= option (eapi/get-element-text-el *driver* %)))
    first
    (eapi/click-el *driver*)))

lread 2023-04-01T03:50:14.531819Z

@fabrao do you still need help or are you all good now?

lread 2023-03-29T16:48:30.823049Z

Hi, @fabrao thanks for reaching out with a question. I created a fiddle directory to experiment. In this directory I put searchtext.html:

<html>

<body>
A sample from Slack:

<span>
GMT(+00:00)
Universal
</span>

</body>
</html>
WebDriver XPath is kinda limited, but let's explore something that might work for you instead. The setup:
(require '[etaoin.api :as e]
         '[babashka.fs :as fs])

;; open a sessions
(def driver (e/chrome))
;; navigate to your test page
(e/go driver (->> "fiddle/searchtext.html" fs/absolutize (str "file://")))
And now let's try using contains:
(e/get-element-text driver ".//span[contains(text(),'Universal')]")
;; => "GMT(+00:00) Universal"
And the cleanup:
(e/quit driver)
Using contains might not be as specific as you would have liked, but might be sufficient for your use case?