3

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.

Disable images in Selenium ChromeDriver

4 Answers 4

4

For anyone who comes across this and is using chrome headless, here is how to disable images.

options = Selenium::WebDriver::Chrome::Options.new(args: ['headless', '--blink-settings=imagesEnabled=false']) @driver = Selenium::WebDriver.for(:chrome, options: options) 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Hi, bbbco. I have try this answer, but it didn't work. I am using capybara (2.10.1) and
0

The 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

0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.