【问题标题】:Selenium WebDriver/Firefox|Chrome/Java How to disable image loadingSelenium WebDriver/Firefox|Chrome/Java 如何禁用图像加载
【发布时间】:2018-01-17 17:13:47
【问题描述】:

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

【问题讨论】:

    标签: java selenium firefox webdriver


    【解决方案1】:

    火狐

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

    docs找到的线索

    对于设置自定义首选项,我们建议使用 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);
    

    【讨论】:

      猜你喜欢
      • 2015-09-22
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 2015-09-05
      • 2017-07-20
      相关资源
      最近更新 更多