欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ruby下WebDriver的相關(guān)操作指南

 更新時間:2015年07月14日 10:48:03   投稿:goldensun  
這篇文章主要介紹了Ruby下WebDriver的相關(guān)操作指南,同時也介紹了啟動firefox drive加載firebug擴(kuò)展的方法,需要的朋友可以參考下

顯性等待:
 

wait = Selenium::WebDriver::Wait.new(:timeout => 3)
wait.until { driver.find_element(:id => "cheese").displayed? }

 

隱性等待:
 

driver = Selenium::WebDriver.for :firefox
driver.manage.timeouts.implicit_wait = 3 # seconds

 內(nèi)部超時:

WebDriver在內(nèi)部使用http協(xié)議與各種driver發(fā)生交互聯(lián)系。默認(rèn)情況下,Ruby標(biāo)準(zhǔn)庫中的Net::HTTP協(xié)議使用時有60秒默認(rèn)超時時間,如果你調(diào)用Driver去加載一個超過60秒時間的頁面,你會看到一個來自于Net:HTTP的超時錯誤。你可以在啟動瀏覽器前手動配置超時時間。

 

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120 # seconds
driver = Selenium::WebDriver.for(:remote, :http_client => client)

 ruby webdriver 啟動firefox driver時,加載firebug的擴(kuò)展

在官方wiki上看到
Adding an extension
It's often useful to have Firebug available in the Firefox instance launched by WebDriver:
 

profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension("/path/to/firebug.xpi")
driver = Selenium::WebDriver.for :firefox, :profile => profile

 

 于是乎自己嘗試了下,但是呢每次都是提示我firebug.xpi找不到

今天有空倒騰了,問題解決了
其實(shí)是之前的理解錯了,因?yàn)閐r =Selenium::WebDriver.for:ff
啟動ff時,都是初始化一個最簡單的profile,里面不帶有firebug插件的,也就是說,哪怕我們原先在firefox上面安裝了firebug,也是啟動不了的,所以當(dāng)我們需要使用firebug時,才需要加載一個firebug的擴(kuò)展
 

profile.add_extension("/path/to/firebug.xpi")

 至于“/path/to/firebug.xpi”就是firebug.xpi的存放路徑了,我們可以去網(wǎng)上下載一個firebug.xpi(對應(yīng)版本, 我的ff是14,可以使用firebug-1.10.4.xpi,最好使用非firefox瀏覽器下載,不然提示你直接安裝到firefox)
我們可以直接把firefox.xpi存放在我們腳本所存放的路徑,相對路徑和絕對路徑都可以
舉個百度的例子
 

require 'selenium-webdriver'
 
#dr = Selenium::WebDriver.for :ff
profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension("path/to/firebug-1.10.4.xpi") <font color="DarkOrchid">#firefox-1.10.4.xpi存放在與腳本同級的path/to下面</font>
dr = Selenium::WebDriver.for :firefox, :profile => profile
dr.get "http://www.baidu.com"

 這樣子當(dāng)我們需要查看dom結(jié)構(gòu)時,我們就可以直接在打開的測試頁面上調(diào)試?yán)?,不用去新開個firefox去查看dom結(jié)構(gòu)了。

相關(guān)文章

最新評論