Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to download files #103

Open
ImagineImogen opened this issue Oct 27, 2020 · 10 comments
Open

How to download files #103

ImagineImogen opened this issue Oct 27, 2020 · 10 comments

Comments

@ImagineImogen
Copy link

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
Copy link
Author

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?

@dimaqq
Copy link
Contributor

dimaqq commented Oct 27, 2020

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.

@ojii
Copy link
Contributor

ojii commented Oct 28, 2020

Is there a way to use Firefox profiles?

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

@dimaqq
Copy link
Contributor

dimaqq commented Oct 28, 2020

mozilla/geckodriver#1776 and mozilla/geckodriver#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

@ImagineImogen
Copy link
Author

ImagineImogen commented Oct 28, 2020

@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

@ojii
Copy link
Contributor

ojii commented Oct 29, 2020

@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"}})

@ImagineImogen
Copy link
Author

@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.

@dimaqq
Copy link
Contributor

dimaqq commented Oct 29, 2020

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

@ImagineImogen
Copy link
Author

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

@dimaqq
Copy link
Contributor

dimaqq commented Dec 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants