Watir/Selenium - browser.goto 在 Chrome 和 Firefox 上不断收到超时错误 [英] Watir/Selenium - browser.goto keep getting TimeOut error on Chrome and Firefox

查看:23
本文介绍了Watir/Selenium - browser.goto 在 Chrome 和 Firefox 上不断收到超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Watir webdriver 有一个非常烦人的问题..

Got a very annoying problem with Watir webdriver..

我进行了一些调试,发现我总是在简单的 @browser.goto 行上得到 TimeOut::Error,即使我可以直观地看到页面已完全加载...

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

场景是这样的:打开浏览器,转到一个 url,单击几个链接,然后突然在某一时刻,脚本停止继续浏览,等待大约 30 秒以上并抛出错误.Chrome 和 FF 都试过了:Chrome 更糟糕,通常会触发第 2 或第 3 次链接点击;对于 FF,有时需要浏览 10 多页...

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. Tried both Chrome and FF: Chrome is much worse, normally a 2nd or 3nd link clicking will trigger; for FF, sometimes takes 10+ page browsing...

打赌存在一些环境或可比性问题:

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

我的结果是:

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 中存在一个错误,无法正确返回 URL.我让你的例子工作使用:

I think there's a bug in Chromedriver that doesn't return the URL correctly. 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'

这篇关于Watir/Selenium - browser.goto 在 Chrome 和 Firefox 上不断收到超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆