'Selenium code downloads in Linux but not Windows

The following code sets up selenium with chromedriver:

import os
import selenium
print(selenium.__version__)
url = 'https://home.treasury.gov/policy-issues/financing-the-government/interest-rate-statistics'
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(url)

And this code attempts to download a file:

nominal = driver.find_element(By.LINK_TEXT, 'DAILY TREASURY PAR YIELD CURVE RATES')
nominal.click()
dwnld = driver.find_element(By.LINK_TEXT, 'Download CSV')
dwnld.click()

It works perfectly on Linux but not on Windows. Selenium version is 4.0.0 on Linux and 4.1.2 on Windows.

On Linux it downloads to the current directory of the python process. On Windows, I looked in several places but could not find a downloaded file.

What is going on? Is there a way to find out the directory that selenium downloads into?



Solution 1:[1]

chromedriver.exe in Windows does not accept the --headless option. The code works after that option is removed as shown below:

import os
import selenium
print(selenium.__version__)
url = 'https://home.treasury.gov/policy-issues/financing-the-government/interest-rate-statistics'
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get(url)
nominal = driver.find_element(By.LINK_TEXT, 'DAILY TREASURY PAR YIELD CURVE RATES')
nominal.click()
dwnld = driver.find_element(By.LINK_TEXT, 'Download CSV')
dwnld.click()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1