• <bdo id='PeLKa'></bdo><ul id='PeLKa'></ul>

    <small id='PeLKa'></small><noframes id='PeLKa'>

    <tfoot id='PeLKa'></tfoot>

      1. <legend id='PeLKa'><style id='PeLKa'><dir id='PeLKa'><q id='PeLKa'></q></dir></style></legend>
      2. <i id='PeLKa'><tr id='PeLKa'><dt id='PeLKa'><q id='PeLKa'><span id='PeLKa'><b id='PeLKa'><form id='PeLKa'><ins id='PeLKa'></ins><ul id='PeLKa'></ul><sub id='PeLKa'></sub></form><legend id='PeLKa'></legend><bdo id='PeLKa'><pre id='PeLKa'><center id='PeLKa'></center></pre></bdo></b><th id='PeLKa'></th></span></q></dt></tr></i><div id='PeLKa'><tfoot id='PeLKa'></tfoot><dl id='PeLKa'><fieldset id='PeLKa'></fieldset></dl></div>

        在 Selenium Google ChromeDriver 中禁用图像

        时间:2023-09-14

          • <tfoot id='GFllN'></tfoot>
              <tbody id='GFllN'></tbody>

              <small id='GFllN'></small><noframes id='GFllN'>

              • <legend id='GFllN'><style id='GFllN'><dir id='GFllN'><q id='GFllN'></q></dir></style></legend>
                <i id='GFllN'><tr id='GFllN'><dt id='GFllN'><q id='GFllN'><span id='GFllN'><b id='GFllN'><form id='GFllN'><ins id='GFllN'></ins><ul id='GFllN'></ul><sub id='GFllN'></sub></form><legend id='GFllN'></legend><bdo id='GFllN'><pre id='GFllN'><center id='GFllN'></center></pre></bdo></b><th id='GFllN'></th></span></q></dt></tr></i><div id='GFllN'><tfoot id='GFllN'></tfoot><dl id='GFllN'><fieldset id='GFllN'></fieldset></dl></div>
                  <bdo id='GFllN'></bdo><ul id='GFllN'></ul>
                • 本文介绍了在 Selenium Google ChromeDriver 中禁用图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在通过 Selenium 和 c# 使用 Google chrome 时禁用图像?

                  How does one disable images in Google chrome when using it through Selenium and c#?

                  我尝试了 6 种方法,但都没有奏效.我什至尝试过 this StackOverflow 问题的答案,但我认为信息在它已经过时了.

                  I've attempted 6 ways and none worked. I've even tried the answer on this StackOverflow question, however I think the info in it is out of date.

                  • Chrome 驱动程序:V2.2
                  • Chrome 版本:V29.0.1547.66 m
                  • 硒:V2.35

                  我所做的所有尝试都不会导致异常,它们运行正常但仍然显示图像:

                  All the attempts I've made don't cause exceptions, they run normally but still display images:

                  尝试 1:

                  ChromeOptions co = new ChromeOptions();
                  co.AddArgument("--disable-images");
                  IWebDriver driver = new ChromeDriver(co);
                  

                  尝试 2:

                  DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
                  capabilities.SetCapability("chrome.switches", new string[1] { "disable-images" });
                  

                  尝试 3:

                  ChromeOptions co = new ChromeOptions();
                  co.AddAdditionalCapability("chrome.switches", new string[1] { "disable-images" });
                  

                  尝试 4:

                  var imageSetting = new Dictionary<string, object>();
                  imageSetting.Add("images", 2);
                  Dictionary<string, object> content = new Dictionary<string, object>();
                  content.Add("profile.default_content_settings", imageSetting);
                  var prefs = new Dictionary<string, object>();
                  prefs.Add("prefs", content);
                  var options = new ChromeOptions();
                  var field = options.GetType().GetField("additionalCapabilities", BindingFlags.Instance | BindingFlags.NonPublic);
                  if (field != null)
                  {
                      var dict = field.GetValue(options) as IDictionary<string, object>;
                      if (dict != null)
                          dict.Add(ChromeOptions.Capability, prefs);
                  }
                  

                  尝试 5:

                  ChromeOptions options = new ChromeOptions();
                  options.AddAdditionalCapability("profile.default_content_settings", 2);
                  

                  尝试 6:

                  Dictionary<String, Object> contentSettings = new Dictionary<String, Object>();
                  contentSettings.Add("images", 2);
                  Dictionary<String, Object> preferences = new Dictionary<String, Object>();
                  preferences.Add("profile.default_content_settings", contentSettings);
                  DesiredCapabilities caps = DesiredCapabilities.Chrome();
                  caps.SetCapability("chrome.prefs", preferences);
                  

                  推荐答案

                  使用http://chrome-extension-downloader.com/ 下载阻止图像"扩展程序 (https://chrome.google.com/webstore/detail/block-image/pehaalcefcjfccdpbckoablngfkfgfgj?hl=en-GB).该扩展程序首先防止图像被下载.现在只需使用以下语句加载它:

                  Use http://chrome-extension-downloader.com/ to download the "Block Image" extension (https://chrome.google.com/webstore/detail/block-image/pehaalcefcjfccdpbckoablngfkfgfgj?hl=en-GB). The extension prevents the image from being downloaded in the first place. Now it's just a matter of loading it using the following statement:

                      var options = new ChromeOptions();
                  
                      //use the block image extension to prevent images from downloading.
                      options.AddExtension("Block-image_v1.0.crx");
                  
                      var driver = new ChromeDriver(options);
                  

                  这篇关于在 Selenium Google ChromeDriver 中禁用图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Selenium WebDriver 滚动到元素 下一篇:Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest

                  相关文章

                  1. <tfoot id='1mN2v'></tfoot>

                    <small id='1mN2v'></small><noframes id='1mN2v'>

                      <bdo id='1mN2v'></bdo><ul id='1mN2v'></ul>
                    <i id='1mN2v'><tr id='1mN2v'><dt id='1mN2v'><q id='1mN2v'><span id='1mN2v'><b id='1mN2v'><form id='1mN2v'><ins id='1mN2v'></ins><ul id='1mN2v'></ul><sub id='1mN2v'></sub></form><legend id='1mN2v'></legend><bdo id='1mN2v'><pre id='1mN2v'><center id='1mN2v'></center></pre></bdo></b><th id='1mN2v'></th></span></q></dt></tr></i><div id='1mN2v'><tfoot id='1mN2v'></tfoot><dl id='1mN2v'><fieldset id='1mN2v'></fieldset></dl></div>

                    1. <legend id='1mN2v'><style id='1mN2v'><dir id='1mN2v'><q id='1mN2v'></q></dir></style></legend>