Skip to content

File download

Two separate problems: making the browser download without a “Save as” dialog, and then getting the file out of the container. WebSummoner helps with both.

Chrome (Java)

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", Map.of(
"profile.default_content_settings.popups", 0,
"download.default_directory", "/home/selenium/Downloads",
"download.prompt_for_download", false,
"download.directory_upgrade", true,
"safebrowsing.enabled", false,
"plugins.always_open_pdf_externally", true
));
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"), chromeOptions);
driver.navigate().to("http://example.com/myfile.odt");

Firefox (Java)

FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("moz:firefoxOptions", Map.of(
"prefs", Map.of(
"browser.helperApps.neverAsk.saveToDisk", "application/octet-stream"
)
));
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"), firefoxOptions);
driver.navigate().to("http://example.com/myfile.odt");

The usual in-container download directory is ~/Downloads.

WebSummoner’s /download API saves you from fiddling with container volumes. With a running session f2bcd32b-d932-4cdc-a639-687ab8e4f840:

GET http://websummoner-host.example.com:4444/download/f2bcd32b-.../myfile.txt
DELETE http://websummoner-host.example.com:4444/download/f2bcd32b-.../myfile.txt

This relies on a small HTTP file server listening on port 8080 inside the browser container — the standard WebSummoner images include it.