Good day,

Faced the following problem: There is a test that

  1. Comes to a specific page.
  2. Shakes the download button.
  3. Goes to the folder and checks the presence of the file according to the specified criteria.

Everything is done without problems, but only until the headless mode is turned on.

The problem is that when you turn on the headless mode, the file downloading process itself does not occur ...

I found some solutions on the Internet, which in principle were similar to each other. After the implementation of one of such workaround, I still ended up at the same place where I was, but the process of downloading the file did not begin.

If someone faced a similar problem and most importantly was able to solve it, then I ask for your help.

Here is an example of the settings that I use for the chrome driver:

if (System.getProperty("selenium.grid").equals("true")) { ChromeDriver chromeDriver; switch (browser) { case "chrome": ChromeDriverService driverService = ChromeDriverService.createDefaultService(); ChromeOptions chromeOptions = new ChromeOptions() .setHeadless(true) .addArguments("--test-type") .addArguments("--disable-extensions"); chromeDriver = new ChromeDriver(driverService, chromeOptions); WebDriverRunner.setWebDriver(chromeDriver); Map<String, Object> commandParams = new HashMap<>(); commandParams.put("cmd", "Page.setDownloadBehavior"); Map<String, String> params = new HashMap<>(); params.put("behavior", "allow"); params.put("downloadPath", System.getProperty("user.home") + "/Downloads/"); commandParams.put("params", params); ObjectMapper objectMapper = new ObjectMapper(); HttpClient httpClient = HttpClientBuilder.create().build(); String command = objectMapper.writeValueAsString(commandParams); String u = driverService.getUrl().toString() + "/session/" + chromeDriver.getSessionId() + "/chromium/send_command"; System.out.println("Link = " + u); HttpPost request = new HttpPost(u); request.addHeader("content-type", "application/json"); request.setEntity(new StringEntity(command)); httpClient.execute(request); break; 

    1 answer 1

    The problem is solved, after updating Google Chrome browser to version 72 beta, the above mentioned workout worked fine in headless mode.