[英]Watir/Selenium - browser.goto keep getting TimeOut error on Chrome and Firefox
Watir Webdriver有一個非常煩人的問題。
我已經調試了一下,發現我總是在簡單的@ browser.goto行上收到TimeOut :: Error,即使我也可以直觀地看到頁面已完全加載...
情況是這樣的:打開瀏覽器,轉到url,單擊一些鏈接,然后突然在某一點,腳本停止繼續瀏覽,等待大約30秒鍾以上並拋出錯誤。 嘗試使用Chrome和FF:Chrome的性能更差,通常會觸發第二或第三鏈接點擊; 對於FF,有時需要10多個頁面瀏覽...
可能存在一些環境或可比性問題:
jd@deskbox:~$ uname -am
Linux deskbox 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
jd@deskbox:~$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
jd@deskbox:~$ rails -v
Rails 3.2.1
jd@deskbox:~$ gem -v
1.8.15
jd@deskbox:~$ gem list|grep webdriver
selenium-webdriver (2.12.0)
watir-webdriver (0.5.3)
有人可以幫忙嗎? 源代碼在這里:
#!/usr/bin/env ruby
require 'watir-webdriver'
require 'pry'
class Search
attr_accessor :browser, :company_url, :company_name
def initialize()
@browser = Watir::Browser.start 'http://www.google.com', :chrome
end
def visit_company_home_via_google(company)
@company_name = company
@browser.goto "http://www.google.com/search?q=#{company}"
link = @browser.div(:id=>'ires').link
return nil unless link.exists?
@browser.goto link.href
@company_url ||= @browser.url
@company_url
end
def logoff()
@browser.close if @browser
end
end
s = Search.new
puts s.visit_company_home_via_google("github")
puts s.visit_company_home_via_google("Mashable")
puts s.visit_company_home_via_google("Barracuda Networks")
s.logoff
我的結果是這樣的:
jd@deskbox:~/cuda$ ./search.rb
https://github.com/
/usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
from /usr/local/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
from /usr/local/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1177:in `request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:627:in `start'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/default.rb:81:in `response_for'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/default.rb:43:in `request'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/common.rb:39:in `call'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:450:in `raw_execute'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:428:in `execute'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
from /usr/local/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.3/lib/watir-webdriver/browser.rb:61:in `goto'
from ./search.rb:17:in `visit_company_home_via_google'
from ./search.rb:33:in `<main>'
我認為Chromedriver中有一個錯誤,無法正確返回網址。 我有您的示例可以使用:
require 'watir-webdriver'
class Search
attr_accessor :browser, :company_name
def initialize
@browser = Watir::Browser.start 'http://www.google.com', :chrome
end
def get_company_url(company, url=nil)
@company_name = company
@company_url = url
@browser.goto "http://www.google.com/search?q=#{company}"
link = @browser.div(:id=>'ires').link
return nil unless link.exists?
@company_url ||= @browser.driver.current_url
end
def logoff()
@browser.close if @browser
end
end
s = Search.new
puts s.get_company_url 'Barracuda Networks'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.