from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.edge.service import Service from selenium.webdriver.chrome.options import Options import time import os DRIVER_PATH = "/usr/bin/chromedriver" service = Service(executable_path=DRIVER_PATH) prefs = { "download.default_directory": os.getcwd(), "download.prompt_for_download": False, "directory_upgrade": True, "safebrowsing.enabled": True, "profile.default_content_settings.popups": 0, "profile.content_settings.exceptions.automatic_downloads.*.setting": 1, "profile.default_content_setting_values.automatic_downloads": 1, "profile.default_content_settings.mimetype_overrides": { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } } options = Options() options.add_argument("--start-maximized") options.add_experimental_option("prefs", prefs) driver = webdriver.Chrome(service=service, options=options) try: driver.get("https://file-examples.com/index.php/sample-documents-download/sample-xls-download/") # Handle the consent popup dialog. consent = driver.find_element(By.CSS_SELECTOR, "button[aria-label='Consent']") consent.click() # Click first download button. download = driver.find_element(By.CSS_SELECTOR, "a.download-button") download.click() # Give it enough time for the download to actually happen! time.sleep(5) finally: driver.quit()