2

I've tried to adapt several existing solutions (1, 2) to the remote Firefox webdriver running in a selenium/standalone-firefox Docker container:

options = Options()
options.set_preference('browser.download.dir', '/src/app/output')
options.set_preference('browser.download.folderList', 2)
options.set_preference('browser.download.manager.showWhenStarting', False)
options.set_preference('browser.helperApps.alwaysAsk.force', False)
options.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
options.set_preference('pdfjs.disabled', True)
options.set_preference('pdfjs.enabledCache.state', False)
options.set_preference('plugin.disable_full_page_plugin_for_types', False)

cls.driver = webdriver.Remote(
    command_executor='http://selenium:4444/wd/hub',
    desired_capabilities={'browserName': 'firefox', 'acceptInsecureCerts': True},
    options=options
)

Navigating and clicking the relevant download button works fine, but the file never appears in the download directory. I've verified everything I can think of:

  • The user in the Selenium container can create files in /src/app/output and those files are visible in the host OS.
  • I can download the file successfully using my desktop browser.
  • The response content type is application/pdf.

What am I missing?

l0b0
  • 55,365
  • 30
  • 138
  • 223
  • 2
    You're missing that file is downloaded to the remote machine or container where the browser is running. – Sers Oct 23 '18 at 21:02
  • save yourself a ton of headaches and use an HTTP client to download files – Corey Goldberg Oct 23 '18 at 21:58
  • @CoreyGoldberg The point is to test the frontend, so that's not an option. – l0b0 Oct 23 '18 at 22:32
  • As I remember, I had to add `'pdfjs.enabledCache.state', false` option to be able to download pdf in firefox, you can take screenshot after download to be sure firefox not open pdf instead of download. Also do you wait to file be downloaded, maybe browser closed before the file is downloaded. – Sers Oct 24 '18 at 06:19
  • in docker is not working, do you know how it comes? – M. Mariscal May 31 '23 at 08:51

1 Answers1

0

It turned out other changes done while researching this were resulting in the server returning a text/plain document rather than a PDF file. For reference, this is the simplest set of options I could get to work:

options.set_preference('browser.download.dir', DOWNLOAD_DIRECTORY)
options.set_preference('browser.download.folderList', 2)
options.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
options.set_preference('pdfjs.disabled', True)
l0b0
  • 55,365
  • 30
  • 138
  • 223