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);
资源
- 哪个ChromeDriver版本与哪个Chrome浏览器版本兼容?
- 从Selenium触发时,Google Chrome无法导航到指定的url
- Selenium点击并不总是有效
- 适用于Chrome和Internet Explorer的GWT Developer插件 – 防止安装错误
- WebDriver与ChromeDriver
- ChromeDriver:自定义Chrome可执行文件路径
- 自动化测试错误:org.openqa.selenium.WebDriverException:disconnected:无法连接到渲染器
- Chrome删除了Java支持
- Chrome错误:您使用的是不受支持的命令行标志: – ignore-certifcate-errors。 稳定性和安全性将受到影响