Is it possible to query on the contents of a tag, like <div>Hello</div> with the map notation in etaoin?
@borkdude (e/get-element-text driver {:id :my-div})
?
I don’t have an id in that page. It’s more like: wait for the element with this class and this content. But I can do it with xpath
something like this: (wait-exists chrome {:tag :div :class "title-text" :content "Hello"})
aah, I see, I dunno then 🙂
but I don’t know if :content
is supported
looking at my tests I also used xpath for this: (e/click driver {:xpath "//a[contains(text(), 'Sign Out')]"})
ok
(exists? chrome "//div[@class='title-text' and 'Hello']")
contains is also a good one, more robust
In addition to etaoin I started using https://github.com/xebia/VisualReview which is awesome
so do you use VisualReview for CSS problems and such?
it gives a visual diff of the current and previous screenshots
so it only tests on the screenshot level
right
that’s actually what we want, we’re not going to use a lot of assertions, but just inspection via screenshots
for now
you may be interested in this thread maybe: https://twitter.com/searls/status/919594505938112512
@borkdude there is an issue for that to extend map notation: https://github.com/igrishaev/etaoin/issues/23
you may share your proposals there. As I see it, for exact text equality we could use
{:tag :div :fn/text "Hello!"}
Why not make it more flexible:
{:tag :div :xpath "contains(text(),'Pico labeler')]"}
so, select the stuff you want and apply xpath to those values?
In my project, we’ve got three common cases: 1. exact text equality 2. HTML class attribute contains a specific class 3 text contains something I think we may add special tags for that cases.
I also wondered about, what does it mean when you pass a vector of maps? Those do not mean sub selections of the previous right?
hm, your example looks well
yes, a vectors means nested selection
ah it does
thanks
so then you could write: [{:tag :div} {:xpath "contains(text(),'Pico labeler')]"}]
already right?
well, probably you could. You may try it repl, there is a function that expands it into a final string expression.
(exists? chrome {:xpath "//div[@class='title-text' and contains(text(),'Pico labeler')]"}) ;; true
(exists? chrome [{:tag :div :class "title-text"} {:xpath "contains(text(),'Pico labeler')"}]) ;; false
what if the second clause would be not a map with :xpath key, but just a string?
still false. what’s the function to expand?
q-xpath
sorry no
brb
".//div[@class='title-text'][contains(text(),'Pico labeler']"
does it work for you?
this form could be expressed as {:tag :div :fn/has-class :title-text :fn/has-text "Pico labeler"}
.
I mean, there are no rules for :fn/...
fields, but I may add them.
I’m in a meeting, I’ll be back this afternoon
I’m back
@igrishaev To come back to your question:
(exists? chrome {:xpath "//div[@class='title-text' and contains(text(),'Pico labeler')]"}) ;; true
(exists? chrome "//div[@class='title-text' and contains(text(),'Pico labeler']") ;; false
I’ll try q-xpath
This works now:
(eta/exists? chrome [{:tag :div :class "title-text"} {:xpath "//*[contains(text(),'Pico labeler')]"}])
The thing was I needed to add the //*
can I scroll with the etaoin lib?