Java Selenium Chrome驱动程序 – 禁用图像加载

我试图运行chrome驱动程序而不加载任何图像,原因很明显。

我在网上发现了一段代码,但我认为它已经过时了

HashMap images = new HashMap(); images.put("images", 2); HashMap prefs = new HashMap(); prefs.put("profile.default_content_settings", images); ChromeOptions options =new ChromeOptions(); options.setExperimentalOption("prefs", prefs); DesiredCapabilities chromeCaps = DesiredCapabilities.chrome(); chromeCaps.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(chromeCaps); 

根本不起作用..

任何帮助都会受到极大的关注

这应该为您禁用图像。

  prefs.put("profile.managed_default_content_settings.images", 2); 

我找到了一个非常好的小插件

 ChromeOptions op = new ChromeOptions(); op.addExtensions(new File("C:\\whatever\\Block-image_v1.0.crx")); driver = new ChromeDriver(op); 

如果有其他人有兴趣,你可以在这里抓住它

检查此代码,

 System.setProperty("webdriver.chrome.driver", Settings.getProperty("ChromeDriverPath")); DesiredCapabilities capabilities= DesiredCapabilities.chrome(); HashMap images = new HashMap(); images.put("images", 2); HashMap prefs = new HashMap(); prefs.put("profile.default_content_setting_values", images); ChromeOptions options= new ChromeOptions(); options.addArguments("--test-type --no-sandbox"); options.addArguments("--enable-strict-powerful-feature-restrictions"); options.setExperimentalOption("prefs", prefs); capabilities.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(capabilities); 

这对我有用

  HashMap images = new HashMap(); images.put("images", 2); HashMap prefs = new HashMap(); prefs.put("profile.default_content_setting_values", images); ChromeOptions chrome_options =new ChromeOptions(); chrome_options.setExperimentalOption("prefs", prefs); DesiredCapabilities chromeCaps = DesiredCapabilities.chrome(); chromeCaps.setCapability(ChromeOptions.CAPABILITY, chrome_options); this.driver = new ChromeDriver(chromeCaps); 

资源