【问题标题】:Why selenium is throwing Net::Read::Timeout error为什么硒会抛出 Net::Read::Timeout 错误
【发布时间】:2021-06-25 04:33:23
【问题描述】:

Selenium 在随机语句上抛出净读取超时错误。我无法找出这是因为代理问题或硒由于其他原因而引发此异常? 我在下面附上了一个回溯。

Net::readtimeout with #<tcpsocket:(closed)>

/usr/local/lib/ruby/2.7.0/net/protocol.rb:217:in `rbuf_fill'
/usr/local/lib/ruby/2.7.0/net/protocol.rb:191:in `readuntil'
/usr/local/lib/ruby/2.7.0/net/protocol.rb:201:in `readline'
/usr/local/lib/ruby/2.7.0/net/http/response.rb:42:in `read_status_line'
/usr/local/lib/ruby/2.7.0/net/http/response.rb:31:in `read_new'
/usr/local/lib/ruby/2.7.0/net/http.rb:1528:in `block in transport_request'
/usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `catch'
/usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `transport_request'
/usr/local/lib/ruby/2.7.0/net/http.rb:1492:in `request'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/navigation.rb:32:in `to'
/var/www/bce-parser/bluecare_express_service.rb:121:in `block (3 levels) in parse_new_orders'
/var/www/bce-parser/bluecare_express_service.rb:118:in `each'
/var/www/bce-parser/bluecare_express_service.rb:118:in `block (2 levels) in parse_new_orders'
/var/www/bce-parser/bluecare_express_service.rb:101:in `each'
/var/www/bce-parser/bluecare_express_service.rb:101:in `block in parse_new_orders'
/var/www/bce-parser/bluecare_express_service.rb:82:in `loop'
/var/www/bce-parser/bluecare_express_service.rb:82:in `parse_new_orders'
/var/www/bce-parser/bluecare_express_service.rb:61:in `call'
run_parser.rb:8:in `<main>'

发生此异常的语句@driver.navigate.to(tracking_page_url)

【问题讨论】:

  • 您能否分享引发此异常的tracking_page_url 值?它是否“随机”与他们中的一些人一起工作,而不是与其他人一起工作?还是总是因为同样的失败而失败?
  • 谢谢 benj-p。是的,它随机适用于其中一些。这是一个代理问题,代理服务器在给定的时间范围内没有响应

标签: ruby-on-rails ruby selenium selenium-webdriver watir


【解决方案1】:

您必须增加页面加载超时,它等待默认时间为 60 秒,但您可以通过以下代码增加页面加载超时

client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :chrome,http_client: client

现在您的代码将等待 120 秒以等待由 #click 引起的任何页面加载,并等待通过 goto 方法加载 url。

【讨论】:

  • 谢谢,我已经试过了,这个问题没有解决。
  • 你的 selenium 版本是什么?
  • Selenium 版本:3.142 Chrome 版本:88
【解决方案2】:

更改了 _url => _path

当我访问 root_url 时,我在 Rails 系统测试期间遇到了异常,但 root_path 没问题

I set the default_url in the test environment to localhost:3000 but didn't change anything for me.

【讨论】:

    猜你喜欢
    • 2018-07-26
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 2019-06-13
    • 2021-06-17
    • 2015-02-25
    • 1970-01-01
    相关资源
    最近更新 更多