Reputation: 146
I have a selenium test that requires a file download. I am achieving it by retrieving a url for the download from a page web-element and then doing
driver.get(<url>)
This works just fine with the regular chrome but as I switch to headless chrome I am getting the file downloaded without retrieving a url for the download from the page. The download happens automatically just by navigating to the page. While this is fine for the test I want to know why this is happening with headless chrome
ChromeDriver 99.0.4844.51
Selenium 3.141.0
Python 3.10
Headless Chrome Settings:
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ "--disable-popup-blocking", "--disable-notifications", "--headless", "--disable-web-security", "--no-sandbox", "--disable-dev-shm-usage", "--disable-background-timer-throttling", "window-size=1920x1480", "--remote-debugging-port=9222" ],
"extensions": [ ],
"prefs": {
"download.default_directory": "/Users/Imran.Ali/downloads",
"download.directory_upgrade": true,
"download.prompt_for_download": false,
"plugins.always_open_pdf_externally": true,
"safebrowsing.disable_download_protection": true,
"safebrowsing.enabled": false
}
},
"platform": "ANY",
"unhandledPromptBehavior": "accept",
"version": ""
Regular Chrome Settings
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ "--disable-popup-blocking", "--disable-notifications" ],
"extensions": [ ],
"prefs": {
"download.default_directory": "/Users/Imran.Ali/downloads"
"download.directory_upgrade": true,
"download.prompt_for_download": false,
"plugins.always_open_pdf_externally": true,
"safebrowsing.disable_download_protection": true,
"safebrowsing.enabled": false
}
},
"platform": "ANY",
"unhandledPromptBehavior": "accept",
"version": ""
Upvotes: 2
Views: 1977
Reputation: 1057
Selenium and Headless Chrome can't download files automatically except under some circumstances. This is most likely due to the website itself, not from Selenium or Chrome. Likewise with cases where we cannot download files using Selenium and Headless Chrome. Often this is due to the web itself. More specific reasons are being investigated further.
Upvotes: 1