arsenic icon indicating copy to clipboard operation
arsenic copied to clipboard

How to download files

Open ImagineImogen opened this issue 5 years ago • 10 comments

I'm trying to download files with Arsenic and I don't know how to manage the Firefox pop-up window await session.get_alert_text() gives me NoSuchAlert error, await session.get_window_handles returns only the active window and no pop-up. What's the best way to deal with it?

ImagineImogen avatar Oct 27 '20 16:10 ImagineImogen

after reading about the topic it is clear why this window is never present in window handles, but still not clear what to do with it. Is there a way to use Firefox profiles?

ImagineImogen avatar Oct 27 '20 21:10 ImagineImogen

re: alert, I think it makes sense that there's no alert, because it's a download, not a javascript alert().

for the rest, I must admit that I don't know... maybe @ojii has an idea.

dimaqq avatar Oct 27 '20 23:10 dimaqq

Is there a way to use Firefox profiles?

Firefox(**{"moz:firefoxOptions": {"profile": PATH_TO_PROFILE}})

ojii avatar Oct 28 '20 01:10 ojii

https://github.com/mozilla/geckodriver/issues/1776 and https://github.com/mozilla/geckodriver/issues/1707 have snippets to configure Firefox to download files automatically without a popup.

Looks like the implied advice is still the same†, to configure the browser not to show a dialog when downloading files.

† stackoverflow advice from 2009 https://stackoverflow.com/a/1176389/705086

dimaqq avatar Oct 28 '20 02:10 dimaqq

@ojii unfortunately, passing the profile doesn't work, it either doesn't do anything like here #30 (for me it throws an error arsenic.errors.SessionStartError: unknown error: Invalid byte 58, offset 1.) or opens the index of the profile folder in the browser (if I use browsers.Firefox(**{'moz:firefoxOptions': {'args': ["profile", r"C:\Users\Path\to\Profile]}})) @dimaqq thanks for the links, I configured my Firefox to start downloading without pop-up. It is also working when I pass this configured profile to Selenium. I just cannot get it to work with Arsenic. Here it was also not possible to use Firefox capabilities #61

ImagineImogen avatar Oct 28 '20 19:10 ImagineImogen

@ojii unfortunately, passing the profile doesn't work, it either doesn't do anything like here #30 (for me it throws an error arsenic.errors.SessionStartError: unknown error: Invalid byte 58, offset 1.) or opens the index of the profile folder in the browser (if I use browsers.Firefox(**{'moz:firefoxOptions': {'args': ["profile", r"C:\Users\Path\to\Profile]}}))

It should be browsers.Firefox(**{'moz:firefoxOptions': {"profile": r"C:\Users\Path\to\Profile"}})

ojii avatar Oct 29 '20 01:10 ojii

@ojii I tried that back then, and it gave me TypeError: Object of type set is not JSON serializable. The correct way to start it is browsers.Firefox(**{'moz:firefoxOptions': {'args': ["-profile", r"C:\Users\Path\to\Profile]}}), then I see in the logs that the driver has started with this profile (instead of a newly created one). But it doesn't do anything, just like what is mentioned here #30 . I checked how it is done in Selenium, and they are cloning the passed profile directory in the one created by webdriver. Unfortunately, Firefox profiles don't work for Arsenic yet.

ImagineImogen avatar Oct 29 '20 07:10 ImagineImogen

Looks like a silly typo, which would explain the "set" type in the error: - "profile", r"C:..."profile": r"C:...

dimaqq avatar Oct 29 '20 08:10 dimaqq

No, the string @ojii provided is not working, giving either arsenic.errors.SessionStartError: unknown error: Invalid byte 58, offset 1 or TypeError: Object of type set is not JSON serializable browsers.Firefox(**{'moz:firefoxOptions': {'args': ["-profile", r"C:\Users\Path\to\Profile]}}) is working, but it is starting the webdriver with the profile provided, but it doesn't do anything, it cannot perform the GET request. Another user had the same issue #30

ImagineImogen avatar Oct 29 '20 09:10 ImagineImogen

I believe your analysis is correct, a duplicate of #30, where PR would be very welcome 🙏

dimaqq avatar Dec 16 '20 01:12 dimaqq