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

标签 java selenium firefox webdriver

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

最佳答案

火狐

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

线索在 docs 中找到

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

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

关于java - Selenium WebDriver/Firefox|Chrome/Java 如何禁用图像加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48306556/

相关文章:

css - SASS - CSS - 动画在 chrome 中有效,在 firefox 中无效

java - Spring Boot 本地化来自 RestController 的每个响应参数

unit-testing - 测试 Web 应用程序的 UI?

java - firefox selenium webdriver 错误

java - Selenium waitForPageToLoad 中的竞争条件?

internet-explorer - 本地系统帐户的 IE 保护模式

只适用于 Chrome 的 CSS?

java - 从 .crt 和 .key 文件创建 .jks 是可能的

java - 使用共享的 ExecutorService 作为任务队列,我如何知道作业何时完成?

java - 如何解密从 Shibboleth IdP 收到的 SAMLResponse