Reputation: 87
I'm working on a simple script that downloads a file from some URL and it needs to be stored at a desired location. Somehow I keep running into firefox's download dialog. I've created a FirefoxProfile():
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/path/to/file')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
"application/pdf")
The snippet above is in like a thousand other SO solutions, so i've been banging my head for hours now. I'm hoping that somebody who is more involved with Selenium knows whats up.
I'm currently on Python 3.4.8, 3.5 and 3.6 give the same results.
Solution:
add profile.set_preference("pdfjs.disabled", True)
Upvotes: 0
Views: 66
Reputation: 17553
You may missing assigning the profile to driver
driver = webdriver.Firefox(firefox_profile=profile)
Check if path is correct
/path/to/file
You care put pdf , is your file is pdf only?
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
"application/pdf")
More file format flags :
"browser.helperApps.neverAsk.saveToDisk","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml")
Use below code:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", 'PATH TO DESKTOP')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
"application/pdf")
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("Name of web site")
Upvotes: 0
Reputation: 1042
I think it's because the default setting in Firefox for pdf is - preview.
Try to add below code:
profile.set_preference("pdfjs.disabled", True)
profile.set_preference("plugin.scan.Acrobat", "99.0")
profile.set_preference("plugin.scan.plid.all", False)
profile.set_preference("plugin.disable_full_page_plugin_for_types", "application/pdf")
Upvotes: 3