Fork me on GitHub
#etaoin
<
2023-03-28
>
fabrao19:03:05

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

fabrao19:03:14

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

fabrao19:03:29

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

lread16:03:30

Hi, @U0YJJPFRA 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?

fabrao17:03:11

@UE21H2HHD 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*)))

lread03:04:14

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