【问题标题】:C# Selenium download file that "can harm my computer"C# Selenium 下载文件“可能会伤害我的电脑”
【发布时间】:2018-04-17 14:05:25
【问题描述】:

我尝试下载我的 Chrome 识别为恶意或有可能损害我的 PC 的“.cert”文件。是否有可能禁用以下框: Popup Box。 我已经搜索并尝试了很多可能的解决方法或解决方案,但到目前为止都没有奏效。我的 Chromeoptions 是这样的:

var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
chromeOptions.AddUserProfilePreference("safebrowsing.enabled", true);

我正在使用以下 Nuget 包:

  • Selenium WebDriver 版本 3.9.1
  • Selenium.Chrome.Webdriver 2.37 版

最好的问候, 康迪

【问题讨论】:

  • 不要使用自签名证书或将签名者添加到受信任的根存储库。
  • 这不是我的选择,因为我的应用程序是 VPN Server 的测试自动化,它会在每次安装后生成自签名证书,因此每次设置后签名者都会更改。
  • 您是说不能将从受信任的来源(Verisign、GoDaddy 等)生成的证书添加到生成不相关的自签名证书的站点吗?
  • 对不起,我刚看到图片。我不认为这与网站 SSL 证书有关。
  • 您是否尝试将证书添加到 .ZIP 文件中?

标签: c# selenium selenium-chromedriver


【解决方案1】:

Chrome v.85、webdriver v.3.141

为我工作:

ChromeOptions options = new ChromeOptions(); 
options.AddUserProfilePreference("safebrowsing", "disabled");
driver = new ChromeDriver(Environment.CurrentDirectory, options);

【讨论】:

    【解决方案2】:

    这可以使用 Selenium.WebDriver 3.11.2 和 Selenium.Chrome.WebDriver 2.37.0 以及禁用下载保护。空白的 .crt 仍然托管在我的博客上,因此您可以根据需要进行测试。

     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--safebrowsing-disable-download-protection");
     options.AddUserProfilePreference("safebrowsing", "enabled");
    
     using (var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory), options))
     {
        driver.Url = "https://www.kitson-online.co.uk/test.crt";
     }
    

    【讨论】:

    • 我尝试了您的解决方案,但它似乎对我不起作用,我不知道为什么。也许是因为我的 .cert 文件是 CA 证书,但我无法想象这就是原因。使用您的 URL 和您的 test.crt 它正在工作,对我来说,它已经与其他具有 .p12 的证书一起使用,我只是对这个自签名 CA 证书有问题。
    • 好吧,我只能说,如果我启用下载保护,我会收到您所说的错误。如果我删除下载保护,它可以正常工作而不会出错。您使用的是哪个版本的 Chrome 驱动程序?从这里尝试 2.9 chromedriver.storage.googleapis.com/index.html?path=2.9
    • 好吧,它没有“更好”,但我发现:如果我通过 html 按钮导出 CA,无论我做什么,都会出现这个警告。如果我通过该按钮后面的链接导出 CA 并执行:driver.navigate("URLofCertificate");它在没有任何警告的情况下工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多