I'm having difficulty downloading a PDF file from a webpage using Selenium 3.8, Firefox 57 and Python 2.7. If I do not manually change the Firefox profile download settings from "Always ask you where to save files" to a specific location, the download pop-up box will still appear and the files will not automatically be downloaded to a specified folder.
I have checked this StackO post and I'm not sure what I am missing. Do I need marionette installed and set up? I do have already set up the geckodriver executable.
Here is my code:
profile = webdriver.FirefoxProfile("/Users/USERNAME/Library/Application Support/Firefox/Profiles/NAME")
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference("browser.helperApps.neverAsk.openFile", 'application/pdf')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
profile.set_preference('browser.download.dir', download_to_location)
browser = webdriver.Firefox(profile)
download_to_location = "PATH_TO_FOLDER_WITHIN_DIRECTORY"
for race in races:
browser.get(race)
try:
[browser.find_element_by_xpath(lxp).click() for lxp in download_from_xpaths]
except:
pass