SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.42k stars 8.15k forks source link

[🚀 Feature]: Add Method to RemoteWebDriver for Downloading Files as Byte Array #14347

Closed Vei0vis closed 1 month ago

Vei0vis commented 1 month ago

Feature and motivation

I am proposing the addition of a new method to the Selenium RemoteWebDriver that allows for the downloading of files directly into memory as a byte[]. Currently, the downloadFile method in the RemoteWebDriver class requires specifying a target directory to save the file, which then needs to be read back into memory if in-memory processing is needed. This additional step of saving to and reading from a temporary directory adds unnecessary complexity and I/O overhead.

The motivation behind this feature is to streamline workflows where immediate in-memory processing of downloaded files is needed. By providing the file content as a byte[] directly, it will eliminate the need for temporary storage and make the process more efficient and straightforward. This is particularly useful in scenarios where downloaded files need to be processed or validated on the fly.

Usage example

Here is how the proposed feature could be used in a Java code snippet:

// Current method requires specifying a target directory
((HasDownloads) driver).downloadFile(downloadableFile, targetDirectory);

// Proposed new method to get the file as byte array
byte[] fileData = ((HasDownloads) driver).downloadFile(downloadableFile);
github-actions[bot] commented 1 month ago

@Vei0vis, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 1 month ago

You can still get the content from the HttRespose directly. There is an example in the documentation that allows you to do that.

https://www.selenium.dev/documentation/grid/configuration/cli_options/#enabling-managed-downloads-by-the-node

We won't add the requested feature, as you can manipulate it in the example shown above.

github-actions[bot] commented 3 weeks ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.