我正在无头Chrome中下载文件,但是当我在无头chrome中运行时,它实际上并没有下载,在另一种情况下,我必须download/save/printToPDF
显示在新标签中,就像我们使用< kbd> CTRL + S 。
我在下面尝试过,但是没有用
ChromeOptions options = new ChromeOptions ();
string screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString ();
string screenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString ();
options.AddArguments ("--headless", "chrome.switches", "--disable-extensions", "--window-size=" + screenWidth + "x" + screenHeight); //For headless Chrome
options.AddUserProfilePreference ("download.prompt_for_download", false);
options.AddUserProfilePreference ("disable-popup-blocking", true);
options.AddUserProfilePreference ("safebrowsing.disable_download_protection", true);
options.AddUserProfilePreference ("download.default_directory", sourcePath);
options.AddUserProfilePreference ("directory_upgrade", true);
WebDriver = new ChromeDriver (options);
var param = new Dictionary<string, object> ();
param.Add ("behavior", "allow");
param.Add ("downloadPath", sourcePath);
((ChromeDriver) WebDriver).ExecuteChromeCommand ("Page.setDownloadBehavior", param);