does etaoin has something for testing downloading of files?
@borkdude file downloading is a difficult subject. I used to write unit tests to check whether a file was downloaded or not.
Unfortunately, I didn’t manage to move that code into the library. There is a issue for that: https://github.com/igrishaev/etaoin/issues/73 I’m going to put there some snippets from my previous project and then move them into the code.
cool, some snippets would already help. I found a stackoverflow answer, but this is selenium specific.
@borkdude jut put snippets into the issue a minute ago, you are welcome to check
thank you, I’ll try 🙂
If Firefox, the main problem was, by default it shows a system dialog that asks you where to save a file. You cannot interact with that dialog.
It is really annoying since to turn this dialog off, you need to pass some magic values into :prefs
map that are described not well.
In chrome, the files are saved automatically by default, but you either know what’s the download path or specify your own one.
Then, after clicking on a file link, you should wait for 5-10 seconds and check whether a folder has such a file.
cool, I’ll try
This works:
(eta/wait-exists *chrome* [{:tag :a}
(bu/contains-text? "Download")])
No exception, returns nil
However, this doesn’t work:
(eta/click *chrome* [{:tag :a}
(bu/contains-text? "Download")])
When I click the a
manually (in the Chrome window), the download starts.Any idea?
This also works:
(eta/visible? *chrome* [{:tag :a}
(bu/contains-text? "Download")])
The anchor is inside a modal, don’t know if that makes any difference.@borkdude it’s probably because of a vector you are trying to find another element into a link. Try to use a single xpath selector
@borkdude smth like this: ".//a[(contains(text(), 'Download'))]"
I’m not sure a vector-like query works 100% right
yeah, that works…. question remains why wait-exists
and visible?
do work with that query though
I remember, exists
does not really mean that an element is visible. But you can click on a visible element only. There might be more then one such links, so maybe you are selecting a wrong one.
try to use wait-visible
instead of wait-exists
also, try to call query-all
against this selector to ensure you really have only one result
but visible?
worked, so this is not relevant to this problem?
Trying…
Hmm, I get two back, you’re right
btw, is that a direct link without any javascript handlers? Because if so, there could be some tricky event that fires on not a link, or some other element.
oh great, try to decrease the scope of your selector then.
it has a javascript handler
so click
only clicks one element, not all selected elements?
I’m surprised that
[{:tag :a}
(bu/contains-text? "Download")]
gives me two results. The other element was not or inside an a
tag.hm, that means a vector form of a query works not so well. I’ll create an issue for that. At the moment, try to pass just an Xpath expression.
yes, thank you
fwiw, the other element was
<h4 class=“modal-title”>Download citations</h4>
ok, this is it: https://github.com/igrishaev/etaoin/issues/105 maybe I’ll reach it someday
I added a simplified test case so you can get rid of all the other code
yes, thanks
This might be a bug too? A query vector with only one element in query-all
crashes:
(eta/query-all *chrome* [{:tag :input
:id “limit”}])
I’m using 0.2.2
, I should probably upgrade first
happens in 0.2.5
as well
good catch, could you add it into the issue please?
no worries, I added
oh sorry, I was in a meeting