当Watir :: Browser.new时,Net :: ReadTimeout错误

时间:2018-09-12 08:34:01

标签: ruby watir irb

我正在尝试启动watir浏览器,

irb(main):001:0> require 'watir'
=> true
irb(main):002:0> browser = Watir::Browser.new

Watir用搜索栏中的data:,写一个新的Chrome浏览器。等待60秒后,浏览器刚刚关闭,并且在控制台中出现此错误:

Net::ReadTimeout: Net::ReadTimeout
    from /usr/lib/ruby/2.3.0/net/protocol.rb:158:in `rbuf_fill'
    from /usr/lib/ruby/2.3.0/net/protocol.rb:136:in `readuntil'
    from /usr/lib/ruby/2.3.0/net/protocol.rb:146:in `readline'
    from /usr/lib/ruby/2.3.0/net/http/response.rb:40:in `read_status_line'
    from /usr/lib/ruby/2.3.0/net/http/response.rb:29:in `read_new'
    from /usr/lib/ruby/2.3.0/net/http.rb:1437:in `block in transport_request'
    from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `catch'
    from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `transport_request'
    from /usr/lib/ruby/2.3.0/net/http.rb:1407:in `request'
    from /usr/lib/ruby/2.3.0/net/http.rb:1400:in `block in request'
    from /usr/lib/ruby/2.3.0/net/http.rb:853:in `start'
    from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/http/default.rb:121:in `response_for'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/http/default.rb:76:in `request'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/http/common.rb:62:in `call'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/bridge.rb:164:in `execute'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/bridge.rb:97:in `create_session'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/remote/bridge.rb:53:in `handshake'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/chrome/driver.rb:48:in `initialize'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver.rb:86:in `for'
    from /var/lib/gems/2.3.0/gems/watir-6.13.0/lib/watir/browser.rb:48:in `initialize'
    from (irb):3:in `new'
    from (irb):3
    from /usr/bin/irb:11:in `<main>'

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

正如您所说的,这是在页面加载时间超过60秒时发生的,您可以通过以下代码来增加页面加载超时时间

client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :firefox,http_client: client
b=Watir::Browser.new driver

现在,对于#click导致的任何页面加载,您的代码都将等待120秒,并且还将等待通过goto方法加载网址。