'headless chrome downloading file without being asked to
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": ""
Solution 1:[1]
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.
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 | ImBIOS |