1

We are trying to verify the downloaded file in headless mode with C#, the file is downloading but not saving in the download path, so my test script is failing.

Any idea for this?

The code is below

ChromeOptions option = new ChromeOptions(); 
option.AddUserProfilePreference("download.default_directory", @"%USERPROFILE%\Downloads"); 
option.AddArgument("--headless"); 
option.AddArgument("--window-size=1920,1080"); 
option.AddArguments("--disable-web-security"); 
option.AddArguments("--allow-running-insecure-content"); 
driver = new ChromeDriver(option);
  • Hi put the script you used to download and verify the file – PDHide Oct 31 at 7:00
0

I had a similar problem recently I had to add extra options to set the download path for headless.

    var options = new ChromeOptions();
    options.AddArgument("--headless");
    options.AddArgument("--disable-extensions");
    options.AddArgument("--disable-gpu");
    options.AddArgument("--disable-dev-shm-usage");
    options.AddArgument("--no-sandbox");
    options.AddArgument("--ignore-certificate-errors");
    options.AddUserProfilePreference("download.default_directory", Path.GetTempPath());
    options.AddUserProfilePreference("download.directory_upgrade", true);
    options.AddUserProfilePreference("download.prompt_for_download", false);

    var driver = new ChromeDriver(options);

    var settingForHeadlessDownloads = new Dictionary<string, object>
    {
        { "behavior", "allow" },
        { "downloadPath", Path.GetTempPath() }
    };
    driver.ExecuteChromeCommand("Page.setDownloadBehavior", settingForHeadlessDownloads);

This answers has some more details, apperently it is a security feature, but is for Python. https://stackoverflow.com/questions/45631715/downloading-with-chrome-headless-and-selenium

  • we tried this already ,still no luck with chrome version 78. – Bendi Vasundhara Oct 31 at 12:24
  • ChromeOptions option = new ChromeOptions(); option.AddUserProfilePreference("download.default_directory", @"%USERPROFILE%\Downloads"); option.AddArgument("--headless"); option.AddArgument("--window-size=1920,1080"); option.AddArguments("--disable-web-security"); option.AddArguments("--allow-running-insecure-content"); driver = new ChromeDriver(option); – Bendi Vasundhara Oct 31 at 12:26
  • What is that last comment? – Niels van Reijmersdal Oct 31 at 12:29
  • we tried above code along with the shared script,but not sure where we are failing – Bendi Vasundhara Oct 31 at 12:39
  • Added my full options code aswell. I am on chrome v77 and cannot upgrade soon to test if it still works. – Niels van Reijmersdal Oct 31 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.