require 'rubygems'
require 'selenium-webdriver'
require 'win32ole'
driver = Selenium::WebDriver.for :firefox
driver.manage.timeouts.implicit_wait = 10
driver.get "https://prod.example.com/"
link_name = wait.until {
element = driver.find_element(:link_text, "Company")
element if element.displayed?
}
link_name.click if link_name
但隨着頁面加載沒有完成我的劇本得到了失敗,每次產生以下錯誤:有沒有辦法停止瀏覽器的頁面加載?
C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout:
:Error (Timeout::Error)
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_r
equest'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1293:in `request'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/http/default.rb:83:in `response_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/http/default.rb:39:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/http/common.rb:40:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/bridge.rb:615:in `raw_execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/bridge.rb:593:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/remote/bridge.rb:561:in `find_element_by'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2/lib/s
elenium/webdriver/common/search_context.rb:42:in `find_element'
from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip
ts/answerlist.rb:29:in `rescue in <main>'
from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip
ts/answerlist.rb:21:in `<main>'
因此我要找說20秒後停止頁面加載,然後打元素正如我在上面的代碼。因爲我檢查頁面何時開始加載,如果我嘗試查看頁面源代碼,我沒有收到任何網頁元素。但是在頁面加載開始之後,如果我從開始到10-12秒關閉它,並嘗試查看網頁源代碼,那麼所有必需的元素。
所以我想做同樣的progamatically。任何想法如何做到這一點?
不要添加評論詢問人們是否可以幫助您。如果有人有答案,他們會添加它。 –