Shubham
Shubham

Reputation: 22319

How to block images in Watir?

I am using Watir for a data fetching job where I don't need any images to be loaded. Is it possible to block them?

Upvotes: 5

Views: 1223

Answers (5)

fguillen
fguillen

Reputation: 38832

  • Watir 7.1.0
  • Selenium 4.1.0
prefs = {
  profile: {
    managed_default_content_settings: {
      images: 2
    }
  }
}

Watir::Browser.new(:chrome, options: { prefs: prefs })

If you need to specify the URL of the Selenium server/grid:

Watir::Browser.new(:chrome, options: { prefs: prefs }, url: url)

Upvotes: 0

Astrit Shuli
Astrit Shuli

Reputation: 657

Use :

webkit: { webprefs: { loads_images_automatically: false } } or profile: { default_content_setting_values: { images: 2 } }

Upvotes: 3

mpz
mpz

Reputation: 1848

I think it can be:

        profile = Selenium::WebDriver::Chrome::Profile.new
        profile['webkit.webprefs.loads_images_automatically'] = false

        @browser = Watir::Browser.new :chrome, :profile => profile

See: http://watir.github.io/docs/chrome/

Upvotes: 3

Endo Takanobu
Endo Takanobu

Reputation: 11

prefs = {
    :profile => {
        :managed_default_content_settings => { 
          :images => 2
        }
    }
}

b = Watir::Browser.new :chrome, :prefs => prefs

Upvotes: 1

Željko Filipin
Željko Filipin

Reputation: 57312

Disable displaying images in the browser Watir drives manually, and then run Watir script. As far as I know, you can not do it from Watir itself.

Upvotes: 1

Related Questions