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.
Asked
Active
Viewed 1,829 times
4 Answers
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)

akaDanPaul
- 283
- 3
- 9
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)

bbbco
- 1,508
- 1
- 10
- 25
-
Hi, bbbco. I have try this answer, but it didn't work. I am using `capybara (2.10.1)` and – timlentse Oct 28 '16 at 09:15
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)

Raj
- 3,051
- 6
- 39
- 57
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

Dorian
- 22,759
- 8
- 120
- 116