I know this question has been asked before...but I've tried multiple approaches and for some reason anything I download from the driver keeps going to my Downloads folder.
Basically I navigate to a website and download something by clicking a download link like so:
result.click()
This downloads the file fine. But I want to download it to a specific directory. I've tried doing these approaches to change the download directory:
driver = webdriver.Firefox()
profile = webdriver.FirefoxProfile()
driver.command_executor._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context")
driver.execute("SET_CONTEXT", {"context": "chrome"})
driver.execute_script("""
Services.prefs.setBoolPref('browser.download.useDownloadDir', true);
Services.prefs.setStringPref('browser.download.dir', arguments[0]);
""", directory)
driver.execute("SET_CONTEXT", {"context": "content"})
and
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", directory)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
Where directory
is my desired location.
Neither of these worked...can anyone explain why or show me how to actually achieve this?
Thanks