I am trying to automate a file download process using Selenium with ChromeDriver, but the file is not being downloaded to the specified directory.Issue: The program runs without any errors, but the file is not being downloaded to the C:/Users/timit/Downloads directory. I verified that the button click is working as expected.
Here is the code I am using:
from selenium import webdriverfrom selenium.webdriver.chrome.service import Servicefrom webdriver_manager.chrome import ChromeDriverManagerfrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport timeimport os # For environment variables# Chrome setup for file downloadchrome_options = Options()chrome_options.add_argument(r"user-data-dir=C:\Users\YourUser\AppData\Local\Google\Chrome\User Data") # Profile pathchrome_options.add_argument("--profile-directory=ProfileName") # Profile nameprefs = {"download.default_directory": "C:/Users/YourUser/Downloads","download.prompt_for_download": False,"download.directory_upgrade": True,"safebrowsing.enabled": True}chrome_options.add_experimental_option("prefs", prefs)driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)# Login details (not included in this snippet)client_code = os.getenv('CLIENT_CODE', 'YourClientCode') username = os.getenv('USERNAME', 'YourUsername')password = os.getenv('PASSWORD', 'YourPassword')# Navigate to login pagedriver.get('https://login.tharanis.hu/belep.php')# Login stepsdriver.find_element(By.XPATH, '//*[@id="ukod"]').send_keys(client_code)driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(username)driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(password)driver.find_element(By.XPATH, '//*[@id="okb"]').click()time.sleep(5)# Navigate through menu and click downloadWebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="menu_main"]/li[3]'))).click()WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="menu_aruforgalom"]/li[3]/ul/li[1]/a'))).click()WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="rakkeszw_footer"]/table/tbody/tr/td/input'))).click()# Wait for the download to completetime.sleep(10)driver.quit()
What I've Tried:Confirmed that the download directory is correctly set in prefs.Checked the browser settings to ensure downloads don’t require confirmation.Used a fresh ChromeDriver installation.Questions:
What could be causing the file not to download?Are there additional browser or Selenium settings I should configure?Could this issue be related to server-side prompts or authentication?Any help would be appreciated!