etaoin

borkdude 2018-02-09T09:52:52.000346Z

does etaoin has something for testing downloading of files?

igrishaev 2018-02-09T11:17:34.000036Z

@borkdude file downloading is a difficult subject. I used to write unit tests to check whether a file was downloaded or not.

igrishaev 2018-02-09T11:18:31.000349Z

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.

borkdude 2018-02-09T11:19:13.000058Z

cool, some snippets would already help. I found a stackoverflow answer, but this is selenium specific.

igrishaev 2018-02-09T11:22:44.000222Z

@borkdude jut put snippets into the issue a minute ago, you are welcome to check

borkdude 2018-02-09T11:23:24.000257Z

thank you, I’ll try 🙂

igrishaev 2018-02-09T11:23:59.000208Z

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.

igrishaev 2018-02-09T11:25:02.000014Z

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.

igrishaev 2018-02-09T11:26:06.000238Z

In chrome, the files are saved automatically by default, but you either know what’s the download path or specify your own one.

igrishaev 2018-02-09T11:26:44.000033Z

Then, after clicking on a file link, you should wait for 5-10 seconds and check whether a folder has such a file.

borkdude 2018-02-09T11:30:28.000376Z

cool, I’ll try

borkdude 2018-02-09T11:46:24.000201Z

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.

borkdude 2018-02-09T11:46:59.000388Z

Any idea?

borkdude 2018-02-09T11:47:57.000375Z

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.

igrishaev 2018-02-09T12:08:29.000096Z

@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

igrishaev 2018-02-09T12:08:58.000128Z

@borkdude smth like this: ".//a[(contains(text(), 'Download'))]"

igrishaev 2018-02-09T12:10:00.000134Z

I’m not sure a vector-like query works 100% right

borkdude 2018-02-09T12:10:09.000426Z

yeah, that works…. question remains why wait-exists and visible? do work with that query though

igrishaev 2018-02-09T12:12:02.000150Z

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.

igrishaev 2018-02-09T12:12:30.000020Z

try to use wait-visible instead of wait-exists

igrishaev 2018-02-09T12:13:29.000151Z

also, try to call query-all against this selector to ensure you really have only one result

borkdude 2018-02-09T12:13:33.000040Z

but visible? worked, so this is not relevant to this problem?

borkdude 2018-02-09T12:13:41.000119Z

Trying…

borkdude 2018-02-09T12:14:52.000399Z

Hmm, I get two back, you’re right

igrishaev 2018-02-09T12:15:29.000118Z

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.

igrishaev 2018-02-09T12:15:52.000170Z

oh great, try to decrease the scope of your selector then.

borkdude 2018-02-09T12:17:13.000036Z

it has a javascript handler

borkdude 2018-02-09T12:17:40.000127Z

so click only clicks one element, not all selected elements?

borkdude 2018-02-09T12:19:29.000422Z

I’m surprised that

[{:tag :a}
                            (bu/contains-text? "Download")]
gives me two results. The other element was not or inside an a tag.

igrishaev 2018-02-09T12:20:38.000114Z

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.

borkdude 2018-02-09T12:20:47.000204Z

yes, thank you

borkdude 2018-02-09T12:21:31.000008Z

fwiw, the other element was

<h4 class=“modal-title”>Download citations</h4>

igrishaev 2018-02-09T12:22:52.000128Z

ok, this is it: https://github.com/igrishaev/etaoin/issues/105 maybe I’ll reach it someday

borkdude 2018-02-09T12:31:56.000200Z

I added a simplified test case so you can get rid of all the other code

igrishaev 2018-02-09T12:36:27.000185Z

yes, thanks

borkdude 2018-02-09T12:54:50.000195Z

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”}])

borkdude 2018-02-09T12:56:02.000340Z

I’m using 0.2.2, I should probably upgrade first

borkdude 2018-02-09T12:58:15.000296Z

happens in 0.2.5 as well

igrishaev 2018-02-09T13:25:18.000340Z

good catch, could you add it into the issue please?

igrishaev 2018-02-09T14:48:03.000245Z

no worries, I added

borkdude 2018-02-09T16:04:39.000534Z

oh sorry, I was in a meeting