简体   繁体   English

Selenium WebDriver / Firefox | Chrome / Java如何禁用图像加载

[英]Selenium WebDriver/Firefox|Chrome/Java How to disable image loading

为了测试(和带宽!),我需要禁用图像加载。

FireFox 火狐

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

The clue found in docs 文档中找到的线索

for setting custom preferences we recommend using the prefs entry instead of passing a profile. 为了设置自定义首选项,我们建议使用prefs条目而不是传递配置文件。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM