-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Downloading a file in new window in headless ChromeDriver #5722
Comments
@cgoldberg Sounds like there is no solution yet, but I'm not alone. Is there a way to temporarily "un-headless" the headless browser to just download the file? |
@Dejital you can send an HTTP request to fetch the file directly (all the cookies you need are in your driver instance if auth is required) |
@cgoldberg Tried and failed that, since fetching cookies from the driver throws an exception. -- ArgumentException on the Cookie object's Name. Presumably the website I'm authenticating against saves a cookie with no name. Same story for other WebDrivers as well. Somehow they work just fine on their own (authentication), but I can't get the cookies out to make the HTTP request. |
Duplicate of #5159 |
It's easy. Call this enabler function after your switch window for your driver:
|
@ppratikcr7 - Is it possible to call using C#? where I can call this enabler function after the switch window for the driver? |
1 similar comment
@ppratikcr7 - Is it possible to call using C#? where I can call this enabler function after the switch window for the driver? |
ppratikcr7 - Is it possible to call using C#? where I can call this enabler function after the switch window for the driver? |
@avmgan There is already support for executing Chrome Debug Protocol commands in the .NET bindings for ChromeDriver, so not all of the plumbing that is required for Python is required here. The C# equivalent would look something like this:
One small issue I'll take with @ppratikcr7's solution is that it assumes the handle with index 1 will be the new window (cf. |
FWIW, it's not required in Python either :)
|
Is it possible in Java? |
Thank you for the Page.setDownloadBehavior, except I have a new problem. The default browser behavior is when you download file1.xml it download fine, then you download file1.xml again and normally Windows\browser will rename the file to file1 (1).xml (notice the brackets and number count). This number will increment as the same file is downloaded. This is the default behavior. The above code breaks this behavior. How do we get it back? |
@ppratikcr7 how can I do same for java please help. |
I am also facing the same issue. Is there any solution to download multiple files with same name? |
Meta -
OS:
Windows 10
Selenium Version:
Selenium.WebDriver v3.11.0
Selenium.WebDriver.ChromeDriver v2.37.0
Browser:
Headless ChromeDriver
Expected Behavior -
Attempting to download a file using a headless ChromeDriver. The website being "driven" opens a new window on button click, which then triggers a download of a CSV file.
Actual Behavior -
This does open a new Window. However, that window is not in focus in the ChromeDriver. If I switch to the Window, I get an error. There is no file downloaded to the default download directory. The following user preferences are set:
Running the same code in not headless mode does open a new window, which does successfully down the file to the specified default directory (using same user profile preferences as above).
Steps to reproduce -
Page is unfortunately behind authentication and cannot be linked to directly.
The text was updated successfully, but these errors were encountered: