为了测试(和带宽!)目的,我需要禁用图像加载。
最佳答案
火狐
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/