Python Selenium Download Pop Up not getting disabled

24 Views Asked by At

I am trying to write a program in python to download a excel file using selenium. I have everything figured out but I am not able to disable the saveas dialog box that comes after clicking download.

I have tried implementing all the other solutions provided but none of them are working. Below is the snippet where I am initializing my firefox browser.

 # Starting Firefox
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2) # 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory
fp.set_preference("browser.helperApps.alwaysAsk.force", False)
fp.set_preference('browser.download.alwaysOpenPanel',False)
fp.set_preference('browser.download.panel.shown',False)
fp.set_preference('browser.download.Alwaysaskyouwheretosavefiles',False)
mime_types = [
    'text/plain',
    'attachment/vnd.ms-excel',
    'text/csv',
    'application/csv',
    'text/comma-separated-values',
    'application/download',
    'application/octet-stream',
    'binary/octet-stream',
    'application/binary',
    'application/x-unknown',
    'application/excel',
    'attachment/csv',
    'attachment/excel'
    'application/vnd.ms-excel',
    'application/msexcel',
    'application/x-msexcel',
    'application/x-ms-excel',
    'application/x-excel',
    'application/x-dos_ms_excel',
    'application/xls',
    'application/x-xls',
    'application/xlsx'
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", ",".join(mime_types))
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.manager.showAlertOnComplete", False)
fp.set_preference("browser.preferences.instantApply",True)
fp.set_preference("browser.download.manager.showWhenStarting",False)

# Set FireFox
browser = webdriver.Firefox(executable_path=firefox_driver_path,service_log_path=service_log_path, firefox_profile=fp)
wait = WebDriverWait(browser, 10)

I have checked the MIME type also which is 'application/xlsx'. Network MIME

Also I am using my company laptop, so my browser is managed by my company which I think is not allowing me to do this but when I manually disable the 'Always ask where to save' settings in firefox browser, it works but not with the python script. settings

console.warn: services.settings: Ignoring preference override of remote settings server console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment

Also, when checking the log I found these 2 lines, I am not sure why they are coming but just in case if it helps to debug the issue

console.warn: services.settings: Ignoring preference override of remote settings server
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment

I would be very helpful if i am able to implement this as I don't want to use the workaround.

Thanks in advance.

0

There are 0 best solutions below