How to pass browser parameter to Watir
1 answer
As described in the PhantomJS command line page , it is possible to control the loading of images:
- load-images = [true | false] loads all inline images (this is true by default). Also accepted: [yes | not].
During Watir :: Browser initialization, these parameters can be specified as an array in :args
. For example:
args = %w{--load-images=false}
browser = Watir::Browser.new(:phantomjs, :args => args)
Working example:
require 'watir-webdriver'
# Capture screenshot with --load-images=true
browser = Watir::Browser.new(:phantomjs)
browser.goto 'https://www.google.com'
browser.screenshot.save('phantomjs_with_images.png')
# Capture screenshot with --load-images=false
args = %w{--load-images=false}
browser = Watir::Browser.new(:phantomjs, :args => args)
browser.goto 'https://www.google.com'
browser.screenshot.save('phantomjs_without_images.png')
Which gives a screenshot with uploaded images:
And a screenshot without uploaded images:
Note that the Google page image is not loading in the second screenshot (as expected since loading images are set to false).
+8
source to share