Reputation: 29
I have tried this method but its not working .
prefs = {
:profile => {
:managed_default_content_settings => {
:images => 2
}
}
}
Watir::Browser.new :chrome, :prefs => prefs
browser.goto "http://www.example.com"
Upvotes: 2
Views: 213
Reputation: 46836
:prefs
needs to be a key within the :options
Hash:
browser = Watir::Browser.new :chrome, options: {prefs: prefs}
Specifically for disabling images:
browser = Watir::Browser.new(
:chrome,
options: {
prefs: {'webkit.webprefs.loads_images_automatically' => false}
}
)
browser.goto('www.google.com')
p browser.image.loaded?
#=> false
Upvotes: 3
Reputation: 21
I think it is like this
profile = Selenium::WebDriver::Chrome::Profile.new
profile['webkit.webprefs.loads_images_automatically'] = false
@browser = Watir::Browser.new :chrome, :profile => profile
Upvotes: 2
Reputation: 11
First, create a browser object like this:
require 'watir'
browser = Watir::Browser.new
This will open an empty Chrome window (assuming you have it installed) that you can control now.
browser.goto("google.com")
Chrome will navigate to this URL, and the page will load as if you typed the URL yourself.
Now: You can do anything you would normally do on a website with your mouse & keyboard.
Example:
browser.link(text: "All Posts").click
Upvotes: -2