dowload location - Selenium Firefox + Python

Asked

Viewed 152 times

0

I can’t change the default download location in Firefox using Selenium the code is like this:

from selenium import webdriver

fp = webdriver.FirefoxProfile()
fp.set_preference('browser.download.folderList', 2)
fp.set_preference('browser.download.manager.showWhenStarting', False)
fp.set_preference('browser.download.dir', r'C:\Users\Martini\Documents')

fp.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/zip")

firefox = webdriver.Firefox(fp)

I have tested in other places, tried to take the r and let the , but nothing worked. All downloads go to the default folder in the Downloads folder.

1 answer

0


The code seems correct, maybe the file type downloaded may not be coming with Mimetype of type "application/zip". See on this site all MIME Existing types.

Solution: You can put more Mimetypes on the same line, depending on the server configuration may be coming as octet-stream.

Try changing the line as below, see if it solves the problem:

profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/zip;application/octet-stream;application/x-gzip")
  • 1

    That’s right, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.