Hello all, I'm thinking how to query this element:
<span>
GMT(+00:00)
Universal
</span>.//span[text()[2],'Universal'] ?
@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*)))
@fabrao do you still need help or are you all good now?
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?