How do I automatically download files from a pop up dialog using selenium-python?

SeleniumAutomation TestingTesting Tools

We can automatically download files from a pop up dialog using Selenium webdriver with Python. After clicking the download link, a dialog box appears for the user to select various options to Save the file.

We have to programmatically configure the path where the download has to be performed such that every time the Firefox browser is launched, the Firefox profile is proper to perform the download at the desired location.

Open the address bar of Firefox, and enter about:config and press Enter . All the browser preferences shall be available with Edit and Toggle buttons. We shall use the Firefox Options class to set the download preferences for the browser.


from selenium import webdriver
from selenium.webdriver.firefox.options import Options
#object of Options class
op = Options()
#save file to path defined for recent download with value 2
#disable display Download Manager window with false value
op.set_preference("", False)
#download location
#MIME set to save file to disk without asking file type to used to open file
#set geckodriver.exe path
driver = webdriver.Firefox(executable_path="C:\\geckodriver.exe",
#launch URL
#click download link
l = driver.find_element_by_link_text("xls-sample1.xls")


The file downloaded at the declared location.

Published on 01-Feb-2021 16:17:42