geckodriver icon indicating copy to clipboard operation
geckodriver copied to clipboard

Allow to prevent opening of files after download

Open dschmidt opened this issue 2 years ago • 2 comments

I currently cannot make selenium download a file without firefox opening it after the download. It works on my desktop system and I've tracked down the difference to be this setting in my handlers.json:

{
  "mimeTypes": {
    "application/x-rpm": {
            "action": 0,
            "extensions": [
                "rpm"
            ]
    }
}

(when I remove it from that file, it's opened automatically. If I readd it, the file is not opened anymore - so I'm pretty sure, this is the right/relevant setting)

I could not find a relevant preference that could be set through any non-deprecated api. Apparently @lukewiwa came to the same conclusion here: https://github.com/SeleniumHQ/selenium/issues/9997#issuecomment-967800646

I'd be super happy if this was possible already and I just couldn't figure it out... just let me know. Thanks in advance!

System

  • Version: geckodriver 0.30.0 (d372710b98a6 2021-09-16 10:29 +0300)
  • Platform: Linux 5.16.15
  • Firefox: 98.0
  • Selenium: 4.1.1

Testcase

const {Builder, By, Key, until} = require('selenium-webdriver');
const { Options  } = require('selenium-webdriver/firefox')

(async function helloSelenium() {
    const options = new Options()
        .setPreference('browser.download.folderList', 2) // custom location
        .setPreference('browser.download.manager.showWhenStarting', false)
        .setPreference('browser.download.dir', '/tmp/foobar')
        .setPreference('browser.helperApps.neverAsk.saveToDisk', 'application/x-redhat-package-manager')
        .setPreference('browser.helperApps.neverAsk.openFile', 'application/x-redhat-package-manager')

    let driver = await new Builder().withCapabilities(options).build();
    driver.manage().setTimeouts({implicit: 3 })


    await driver.get('http://download.opensuse.org/tumbleweed/repo/src-oss/src/');

    const locator = By.css(".by-name > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(2) > a:nth-child(1)")
    let link = await driver.wait(until.elementLocated(locator),10000);
    await link.click()
})();

Stacktrace

Trace-level log

dschmidt avatar Mar 21 '22 17:03 dschmidt

Any news on this?

bswhb avatar Apr 29 '23 07:04 bswhb

this is needed, or an option to force downloads

hacktivista avatar Jun 14 '23 19:06 hacktivista