Ruby下WebDriver的相關操作指南_ruby專題

來源:互聯網
上載者:User

顯性等待:
 

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

 

隱性等待:
 

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

 內部逾時:

WebDriver在內部使用http協議與各種driver發生互動聯絡。預設情況下,Ruby標準庫中的Net::HTTP協議使用時有60秒預設逾時時間,如果你調用Driver去載入一個超過60秒時間的頁面,你會看到一個來自於Net:HTTP的逾時錯誤。你可以在啟動瀏覽器前手動設定逾時時間。

 

client = Selenium::WebDriver::Remote::Http::Default.newclient.timeout = 120 # secondsdriver = Selenium::WebDriver.for(:remote, :http_client => client)

 ruby webdriver 啟動firefox driver時,載入firebug的擴充

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

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

 

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

今天有空倒騰了,問題解決了
其實是之前的理解錯了,因為dr =Selenium::WebDriver.for:ff
啟動ff時,都是初始化一個最簡單的profile,裡面不帶有firebug外掛程式的,也就是說,哪怕我們原先在firefox上面安裝了firebug,也是啟動不了的,所以當我們需要使用firebug時,才需要載入一個firebug的擴充
 

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

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

require 'selenium-webdriver' #dr = Selenium::WebDriver.for :ffprofile = Selenium::WebDriver::Firefox::Profile.newprofile.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 => profiledr.get "http://www.baidu.com"

 這樣子當我們需要查看dom結構時,我們就可以直接在開啟的測試頁面上調試啦,不用去新開個firefox去查看dom結構了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.