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;
}
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: