【问题标题】:How can I avoid program termination caused by watir-webdriver timeout error while loading a webpage?如何避免在加载网页时因 watir-webdriver 超时错误导致程序终止?
【发布时间】:2012-08-16 03:20:57
【问题描述】:

我使用 watir-webdriver 来自动化一些日常任务,最近我完美的工作脚本在开始时中止了。当我使用 browser.goto "webpage" 时,网页没有完全加载,因为页面底部有一个计数器,并且计数器服务似乎暂时关闭。有时它会加载,有时不会。否则,我需要的所有 html 元素都已加载且可见,但页面无法完全加载,因此 30 秒后我总是收到 tiemout 错误,并且我的 Ruby 脚本以以下错误消息终止:

/opt/ruby1.8/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill': execution expired (Timeout::Error)
    from /opt/ruby1.8/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
    from /opt/ruby1.8/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
    from /opt/ruby1.8/lib/ruby/1.8/net/protocol.rb:126:in `readline'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:2017:in `read_new'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:1051:in `request'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:1037:in `request'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:543:in `start'
    from /opt/ruby1.8/lib/ruby/1.8/net/http.rb:1035:in `request'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in `response_for'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:in `request'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
    from /opt/ruby1.8/lib/ruby/gems/1.8/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:63:in `goto'

有什么方法可以避免程序终止并使用未完全加载的页面?我的意思是如果可能的话,任何超时异常处理,最重要的是我的 Ruby 脚本继续没有终止。我试过这个,但没有奏效,因为我只是 3 天的 ruby​​ 程序员:

begin
  browser.goto "http://example.com"
rescue Watir::Exception::NavigationException => e #catch the Exception
  puts "Page did not load: #{e}" 
  # program continues from here 
end

【问题讨论】:

    标签: exception exception-handling timeout webdriver watir


    【解决方案1】:

    尝试拯救Timeout::Error 而不是Watir::Exception::NavigationException。

    【讨论】:

      猜你喜欢
      • 2020-07-31
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 2018-03-03
      • 2017-11-16
      相关资源
      最近更新 更多