During the test, a file (.html) will be downloaded from the web application & I have to verify that file by opening it on the browser. In the non-headless mode, my test is working fine. But whenever I'm going to headless mode, that file is not getting downloaded to the download path (i.e. pointed in the "user.dir"). My chrome driver version is 2.44.609538 & selenium version is 3.14.
Asked
Active
Viewed 3,246 times
4
-
Please explain your problem in detail. Is your file downloaded at wrong path? Are you getting some error? Please share the code which you have tried already. You should add [mcve] in question. – Kamal Mar 19 '19 at 09:51
-
When running in the non-headless mode, the file is downloaded in the user directory. The test is running perfectly. The problem begins when I'm running the test in headless mode. – Rishi12 Mar 19 '19 at 13:25
-
"User.dir" changes in headless mode. See https://stackoverflow.com/questions/51168671/screenshot-with-katalon-and-chrome-headless-mode. – Mate Mrše Mar 19 '19 at 14:29
-
My implementation was working well but after I updated the Capybara gem to 3.33.0 and the Selenium gem to 4.0.0.alpha6 I am facing the same problem. – Sergio Prats Nov 12 '20 at 11:09
4 Answers
2
Apparently this could help you
Shawn Button post the answer related with it.

Jerry Brian Osorio Alvarado
- 177
- 11
0
Are you running the test from the command line?
Because, according to an answer to this question and this, when you run it via command line, your user.dir
corresponds to your global user directory (C:\users\username).

Mate Mrše
- 7,997
- 10
- 40
- 77
0
This worked for our ruby implementation:
Capybara.register_driver :scrapping_driver do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--window-size=1366,2000')
options.add_preference(:download, directory_upgrade: true,
prompt_for_download: false,
default_directory: "#{Rails.root}/")
options.add_preference(:browser, set_download_behavior: { behavior: 'allow' })
Selenium::WebDriver::Service.driver_path = Webdrivers::Chromedriver.driver_path
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Pay attention at download behaviour

damuz91
- 1,461
- 2
- 21
- 37
0
I met same situation.
Headless mode is very faster. So your code might be implemented to detect download(DL).
Solution.
- (Current your process?) .click for DL -> Detecting download file generation.
- (My solution) Detecting download file generation -> .click for DL.
I implemented the above mechanism using callback function.

user2058374
- 69
- 1
- 1
- 11