简体   繁体   English

Watir / Selenium-browser.go在Chrome和Firefox上不断出现TimeOut错误

[英]Watir/Selenium - browser.goto keep getting TimeOut error on Chrome and Firefox

Got a very annoying problem with Watir webdriver.. Watir Webdriver有一个非常烦人的问题。

I have debugged a little, and found out I always get TimeOut::Error on a simple @browser.goto line, even I can visually see the page has loaded fully... 我已经调试了一下,发现我总是在简单的@ browser.goto行上收到TimeOut :: Error,即使我也可以直观地看到页面已完全加载...

The scenario is like this: Open a browser, goto a url, click a few links, and then suddenly at one point, the script stops continue browsing, waiting about 30+ seconds and throw errors. 情况是这样的:打开浏览器,转到url,单击一些链接,然后突然在某一点,脚本停止继续浏览,等待大约30秒钟以上并抛出错误。 Tried both Chrome and FF: Chrome is much worse, normally a 2nd or 3nd link clicking will trigger; 尝试使用Chrome和FF:Chrome的性能更差,通常会触发第二或第三链接点击; for FF, sometimes takes 10+ page browsing... 对于FF,有时需要10多个页面浏览...

Bet there is some environment or comparability issue: 可能存在一些环境或可比性问题:

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)

Can someone help on this? 有人可以帮忙吗? Source code here: 源代码在这里:

#!/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

My result is like: 我的结果是这样的:

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

I think there's a bug in Chromedriver that doesn't return the URL correctly. 我认为Chromedriver中有一个错误,无法正确返回网址。 I got your example to work using: 我有您的示例可以使用:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM