如何在Headless Chrome Selenium C#中处理保存/打印pdf

时间:2019-04-01 12:43:56

标签: c# selenium download save headless

我正在无头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);

enter image description here

0 个答案:

没有答案