如何将浏览器参数传递给Watir [英] How to pass browser parameter to Watir

查看:83
本文介绍了如何将浏览器参数传递给Watir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby,并且正在使用Watir的最新gem版本.我计划使用无头浏览器,例如PhantomJS.执行时如何将参数传递给Phantom JS浏览器.

I am using Ruby and am using the latest gem version of Watir. I plan to use headless browser such as PhantomJS. How can one pass paramater to the Phantom JS browser when it get executed.

我的目的是使Phantom JS不需要加载图像.

My purpose is so that Phantom JS do not need to load images.

推荐答案

PhantomJS命令中所述行页面,有一个选项可以控制图像的加载:

As described on the PhantomJS command line page, there is an option to control the loading of images:

-load-images = [true | false]加载所有内联图像(默认为true).也接受:[是|否].

--load-images=[true|false] load all inlined images (default is true). Also accepted: [yes|no].

在初始化Watir :: Browser的过程中,可以在:args键中将这些设置指定为数组.例如:

During the initialization of a Watir::Browser, these settings can be specified, as an array, in the :args key. For example:

args = %w{--load-images=false}
browser = Watir::Browser.new(:phantomjs, :args => args)

一个工作示例:

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 the screenshot with images loaded:

以及未加载图片的屏幕截图:

And the screenshot without images loaded:

请注意,该页面的Google图片未在第二个屏幕截图中加载(这是预期的,因为load-images设置为false).

Notice that the Google image of the page is not loaded in the second screenshot (as expected since load-images was set to false).

这篇关于如何将浏览器参数传递给Watir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆