簡體   English   中英

如何將瀏覽器參數傳遞給Watir

[英]How to pass browser parameter to Watir

我正在使用Ruby並使用最新的Watir寶石版本。 我打算使用像PhantomJS這樣的無頭瀏覽器。 如何在執行時將paramater傳遞給Phantom JS瀏覽器。

我的目的是讓Phantom JS不需要加載圖像。

PhantomJS命令行頁面所述 ,有一個控制圖像加載的選項:

--load-images = [true | false]加載所有內聯圖像(默認為true)。 也接受:[是|否]。

在初始化Watir :: Browser期間,可以在:args鍵中將這些設置指定為數組。 例如:

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')

這給截圖加載了圖片:

phantomjs_with_images.png

沒有加載圖片的截圖:

phantomjs_without_images.png”

請注意,頁面的Google圖像未在第二個屏幕截圖中加載(正如預期的那樣,因為load-images設置為false)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM