Davide Tessarollo
Davide Tessarollo

Reputation: 87

Python Selenium, Firefox driver. Dismiss Open/Save file popup

this is my setup for the driver:

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.firefox.options import Options

#binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
fp = (r'C:\Users\user\AppData\Roaming\Mozilla\Firefox\Profiles\fdjhsjfhd.default')

opts = Options()
opts.profile = fp

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", download_directory) 
fp.set_preference('browser.helperApps.neverAsk.saveToDisk','image/jpeg,image/png,excel,text/plain,csv/text,application/octet-stream')

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

But still I get the pop, as per attached. enter image description here

What is wrong?

Thanks

Found, credits to @cruisepandey:

those are the essential for this purpose:

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.dir", download_directory) 
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.useDownloadDir", True)

Upvotes: 0

Views: 452

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

For one of my project I am using the same version of Selenium and below is my configuration:

profile = FirefoxProfile()
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("browser.helperApps.neverAsk.openFile","text/csv,application/vnd.ms-excel")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
profile.set_preference("browser.download.manager.showWhenStarting", False);
profile.set_preference("browser.download.manager.alertOnEXEOpen", False);
profile.set_preference("browser.download.manager.focusWhenStarting", False);
profile.set_preference("browser.download.folderList", 2);
profile.set_preference("browser.download.useDownloadDir", True);
profile.set_preference("browser.helperApps.alwaysAsk.force", False);
profile.set_preference("browser.download.manager.alertOnEXEOpen", False);
profile.set_preference("browser.download.manager.closeWhenDone", True);
profile.set_preference("browser.download.manager.showAlertOnComplete", False);
profile.set_preference("browser.download.manager.useWindow", False);
profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
profile.set_preference("pdfjs.disabled", True);
driver = webdriver.Firefox(firefox_profile = profile, executable_path = "D:\geckodriver.exe")

Import:

from selenium.webdriver import FirefoxProfile

Upvotes: 2

Related Questions