为了测试(和带宽!)的目的,我需要禁用图像加载。
答案 0 :(得分:5)
<强>火狐强>
FirefoxOptions options = new FirefoxOptions();
options.addPreference("permissions.default.image", 2);
WebDriver driver = new FirefoxDriver(options);
中找到的线索
用于设置自定义首选项,我们建议使用prefs条目而不是传递个人资料。
或强>
DesiredCapabilities capabilities = new DesiredCapabilities();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.image", 2);
capabilities.setCapability("firefox_profile", profile);
WebDriver driver = new FirefoxDriver(capabilities);
<强>铬强>
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);