Selenium WebDriver/Firefox | Chrome/Java如何禁用图像加载 [英] Selenium WebDriver/Firefox|Chrome/Java How to disable image loading

查看:473
本文介绍了Selenium WebDriver/Firefox | Chrome/Java如何禁用图像加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试(和带宽!)的目的,我需要禁用图像加载.

For testing (and bandwidth!) purposes I needed to disable image loading.

推荐答案

FireFox

FirefoxOptions options = new FirefoxOptions();
options.addPreference("permissions.default.image", 2);
WebDriver driver = new FirefoxDriver(options);

文档

对于设置自定义首选项,我们建议使用prefs条目,而不要传递配置文件.

for setting custom preferences we recommend using the prefs entry instead of passing a profile.

OR

DesiredCapabilities capabilities = new DesiredCapabilities();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.image", 2);
capabilities.setCapability("firefox_profile", profile);
WebDriver driver = new FirefoxDriver(capabilities);

Chrome

HashMap<String, Object> images = new HashMap<String, Object>();
images.put("images", 2);
HashMap<String, Object> prefs = new HashMap<String, Object>();
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);
WebDriver driver = new ChromeDriver(chromeCaps);

这篇关于Selenium WebDriver/Firefox | Chrome/Java如何禁用图像加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆