ChromeDriver Ruby禁用图像

ChromeDriver Ruby禁用图像,ruby,image,webdriver,watir,selenium-chromedriver,Ruby,Image,Webdriver,Watir,Selenium Chromedriver,有没有办法用ruby禁用Chromedriver中的图像?还有一个类似的问题,但它涉及到C#,我不确定如何将其移植到ruby 看起来需要将哈希发送到“profile.default\u content\u settings”Chrome配置文件设置。我想试试这样的东西: profile = Selenium::WebDriver::Chrome::Profile.new profile["profile.default_content_settings"] = { :images => '

有没有办法用ruby禁用Chromedriver中的图像?还有一个类似的问题,但它涉及到C#,我不确定如何将其移植到ruby


看起来需要将哈希发送到“profile.default\u content\u settings”Chrome配置文件设置。我想试试这样的东西:

profile = Selenium::WebDriver::Chrome::Profile.new
profile["profile.default_content_settings"] = { :images => '2' }

@driver = Selenium::WebDriver.for(:chrome, :profile => profile)

自@bbbco添加其答案后,要设置的标志已更改。正确的标志是:
“profile.managed\u default\u content\u settings.images”
生成工作代码:

profile = Selenium::WebDriver::Chrome::Profile.new
profile["profile.managed_default_content_settings.images"] = 2

@driver = Selenium::WebDriver.for(:chrome, :profile => profile)

对于任何遇到这种情况并使用chrome headless的人,下面介绍如何禁用图像

options = Selenium::WebDriver::Chrome::Options.new(args: ['headless', '--blink-settings=imagesEnabled=false'])
@driver = Selenium::WebDriver.for(:chrome, options: options)

禁用通知和图像:

Capybara.register_driver :selenium_chrome do |app|
  prefs = { "profile.managed_default_content_settings.notifications" => 2 }

  caps = Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options: { prefs: prefs })

  profile = Selenium::WebDriver::Chrome::Profile.new
  profile["profile.default_content_settings"] = { :images => '2' }

  options = Selenium::WebDriver::Chrome::Options.new(args: ['headless', '--blink-settings=imagesEnabled=false'])

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: caps,
    profile: profile,
    options: options
  )
end

嗨,bbbco。我试过这个答案,但没用。我正在使用
capybara(2.10.1)