Python Set Firefox Preferences for Selenium--Download Location Python Set Firefox Preferences for Selenium--Download Location selenium selenium

Python Set Firefox Preferences for Selenium--Download Location


Ok, I believe I finally figured this mess out. Instead of using the code above, I used the following code which I point to my Firefox profile folder(if you need to update your default profile settings do that in Firefox before running this code):

from selenium.webdriver.firefox.options import Optionsbinary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')fp = (r'C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\oqmqnsih.default')opts = Options()opts.profile = fpfirefox_capabilities = DesiredCapabilities.FIREFOXfirefox_capabilities['marionette'] = Truedriver = webdriver.Firefox(capabilities=firefox_capabilities,firefox_binary=binary, firefox_options = opts)

I ran this code along with my web-scraping code and once I clicked the "Export CSV" link, it automatically downloaded as opposed to the Download Manager window popping up. Feel free to add any feedback.


The initial code is partialy correct. You must set browser.download.folderList value as 2 :

fp = webdriver.FirefoxProfile()fp.set_preference("browser.download.folderList", 2) # 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory fp.set_preference("browser.helperApps.alwaysAsk.force", False)fp.set_preference("browser.download.manager.showWhenStarting",False)fp.set_preference("browser.download.dir", "H:\Downloads") binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')firefox_capabilities = DesiredCapabilities.FIREFOXfirefox_capabilities['marionette'] = Truedriver = webdriver.Firefox(capabilities=firefox_capabilities,firefox_binary=binary, firefox_profile = fp)


the solution for my python script (on raspi 3):

binary = FirefoxBinary('/usr/bin/firefox')driver = webdriver.Firefox(capabilities={'browserName': 'firefox' }, firefox_binary=binary)