Hi Guys,
I am trying to download documents using Selenium with Python from Firefox to a specific folder but I cannot get my code to work as it keeps asking me if I want to download rather than just downloading, any ideas? My code is below.
timeout = 40
downloadPath = ‘C:\TestData_Automated Download Documents’
profile = webdriver.FirefoxProfile()
profile.set_preference(“browser.download.folderList”, 2)
profile.set_preference(“browser.download.manager.showWhenStarting”, False)
profile.set_preference(“browser.download.dir”, downloadPath)
profile.set_preference(“browser.helperApps.neverAsk.openFile”, “application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.ms-excel.sheet.macroEnabled.12, application/vnd.ms-excel.template.macroEnabled.12, application/vnd.ms-excel.addin.macroEnabled.12, application/vnd.ms-excel.sheet.binary.macroEnabled.12”)
profile.set_preference(“browser.helperApps.neverAsk.saveToDisk”, “application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.ms-excel.sheet.macroEnabled.12, application/vnd.ms-excel.template.macroEnabled.12, application/vnd.ms-excel.addin.macroEnabled.12, application/vnd.ms-excel.sheet.binary.macroEnabled.12”)
profile.set_preference(“browser.helperApps.alwaysAsk.force”, False)
profile.set_preference(“browser.download.manager.alertOnEXEOpen”, False)
profile.set_preference(“browser.download.manager.focusWhenStarting”, False)
profile.set_preference(“browser.download.manager.useWindow”, False)
profile.set_preference(“browser.download.manager.showAlertOnComplete”, False)
profile.set_preference(“browser.download.manager.closeWhenDone”, False)
desiredCapabilities = DesiredCapabilities.FIREFOX.copy()
desiredCapabilities[‘firefox_profile’] = profile.encoded
driver = webdriver.Firefox(executable_path=“C:\Users\d.baldwin\AppData\Local\Programs\Python\Python37-32\Lib\geckodriver.exe”,capabilities=desiredCapabilities)
Is there something that I am missing? I am trying to download Excel documents (.xlsx)
Thanks for the help in advance!
Dan