Is there a way to disable images in Chromedriver with ruby? There is a similar question but it deals with C# and I am not exactly sure how to port it over to ruby.
4 Answers
Looks like it requires a hash to be sent to the "profile.default_content_settings" Chrome profile setting. I would try something like this:
profile = Selenium::WebDriver::Chrome::Profile.new profile["profile.default_content_settings"] = { :images => '2' } @driver = Selenium::WebDriver.for(:chrome, :profile => profile) 1 Comment
timlentse
Hi, bbbco. I have try this answer, but it didn't work. I am using
capybara (2.10.1) andThe flag to be set has changed since @bbbco added his answer. The correct flag is: "profile.managed_default_content_settings.images" making the working code:
profile = Selenium::WebDriver::Chrome::Profile.new profile["profile.managed_default_content_settings.images"] = 2 @driver = Selenium::WebDriver.for(:chrome, :profile => profile) Comments
Disabling notifications and images:
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