Chrome Version: Version 117.0.5938.89 (Official Build) (64-bit)

Automation Test Setup:

I'm using Selenium WebDriver with C# for my automation tests.

Issue Description:

In Incognito mode, I used to be able to auto-download PDFs upon button click and perform actions in my test. However, after upgrading to the latest Chrome version, the same driver initialization method in Incognito mode now triggers a Windows SaveAs popup when I attempt to download a PDF upon button click. I've attempted to resolve this by setting the default download directory, but the issue persists.

Request for Assistance:

I need help in avoiding the Windows popup and enabling direct file downloads without the SaveAs popup.

Driver Initialization Method:

Here's the code for the driver initialization method

 private static IWebDriver GetChromeDriver(string userAgent)
 {
var options = new ChromeOptions();
options.AddArgument("incognito");
options.AddArguments("disable-infobars");
// options.AddArguments("--headless");

// Session 0 limit - 1024 x 768
options.AddArguments("--window-size=1024,768");
options.AddArguments("--window-position=0,0");
options.AddArgument($"--user-agent= {userAgent}");

// To disable PDF viewer plugins
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("download.prompt_for_download", false);

if (userAgent.Contains("Mobile"))
{
    // Commenting "EnableMobileEmulation" with Device Name - as it overrides the set Driver's userAgent value
    // Added Device Settings to pass userAgent and explicit values of Mobile Device - To avoid captcha block
    var settings = new ChromeMobileEmulationDeviceSettings(userAgent)
    {
        Height = 731,
        Width = 411,
        PixelRatio = 2.6
    };
    options.EnableMobileEmulation(settings);

    // options.EnableMobileEmulation("Pixel 2");
}
options.AddArgument("--disable-backgrounding-occluded-windows");

// options.BinaryLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe";

var driver = new ChromeDriver(Directory.GetCurrentDirectory(), options, TimeSpan.FromMinutes(3));
return driver;
}
1

There are 1 best solutions below

0
whopacha On

I had the same issue (not using incognito myself) I already had some of these options, but added a few more that I saw and it fixed it.

Try out these options:

        // Profile options for downloading PDF's
        co.AddUserProfilePreference("download.default_directory", this.downloadDir);
        co.AddUserProfilePreference("savefile.default_directory", this.downloadDir);
        co.AddUserProfilePreference("download.prompt_for_download", false);
        co.AddUserProfilePreference("download.directory_upgrade", true);
        ////co.AddUserProfilePreference("download.extensions_to_open", "pdf");
        co.AddUserProfilePreference("safebrowsing.enabled", true);
        co.AddUserProfilePreference("plugins.plugins_disabled", "Chrome PDF Viewer");
        co.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
        co.AddUserProfilePreference("disable-popup-blocking", true);
        co.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);