Reputation: 15
Here is my code. I try to download file using selenium so I want to disable pop up save window but all I've tried didn't work for me. Save window keep showing up. I use Mozilla Firefox and Windows 10.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "./")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "attachment/csv")
binary = '/Users/User/Documents/Geckodriver/geckodriver.exe'
browser = webdriver.Firefox(executable_path = binary, firefox_profile = profile)
If it is important I use Firefox as my regular browser maybe it can somehow affect geckodriver.
I add update line before binary line and it didn't help me.
profile.update_preferences()
I found all these preferences in about:config and they all actually have been applied: example
Actually I try to download mp3 file if this matters
Upvotes: 0
Views: 285
Reputation: 193298
Once you set all the preferences through profile.set_preference()
lines, finally you need to update the preferences using the line:
profile.update_preferences()
So effectively, your code block will be:
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "attachment/csv")
profile.update_preferences()
binary = '/Users/User/Documents/Geckodriver/geckodriver.exe'
browser = webdriver.Firefox(executable_path = binary, firefox_profile = profile)
Upvotes: 0