【问题标题】:Selenium ReadTimeout error while liggin inleenium readtimeout在liggin中的错误
【发布时间】:2020-09-17 22:46:02
【问题描述】:

使用 Selenium + Ruby 构建我的第一个测试。有一个步骤我必须登录。 我正在传递登录名和密码,然后脚本单击“登录”按钮。

登录过程可能需要一段时间(系统细节 - 一直都是这样,没关系)。因此,当我的脚本等待登录时,大约 100 秒后,我的代码会出现错误: /usr/local/Cellar/ruby@2.5/2.5.8/lib/ruby/2.5.0/net/protocol.rb:181:in `rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)

我假设我需要设置类似 timeout 的时间,例如最长 240 秒,但找不到正确的方法。

您能帮我设置一个正确的超时属性吗?

谢谢!

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome
# driver.manage.timeouts.implicit_wait = 240 - Tried it, didn't help
# driver.manage.timeouts.page_load = 240 - 

driver.navigate.to 'https://webiste.com'

#Entering my login and password
driver.find_element(id: 'admin_user_email').send_keys('MY_LOGIN')
driver.find_element(id: 'admin_user_password').send_keys('MY_PASSWORD')

#Clicking Login button and at this step my script breaks after ~100 sec
driver.find_element(id: 'admin_user_submit_action').click

driver.navigate.to 'https://another_URL_after_logged_in'

puts 'You are on the page'

【问题讨论】:

  • 你是在本地运行还是在容器中运行?
  • 我现在在本地运行
  • 你在本地遇到同样的错误吗?
  • 是的,我正在本地机器上运行此代码并收到此错误。我正在尝试找到一种以正确方式增加 TimeOut 的方法

标签: ruby selenium selenium-webdriver


【解决方案1】:

根据 cmets 的要求。这样做可以增加超时时间:

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 240 # Or whatever you need
driver = Selenium::WebDriver.for :chrome, :http_client => client

【讨论】:

  • 成功了!谢谢!你能建议一下吗,为什么你问我在哪里运行它?会有什么不同?或者如果这是一个很长的话题,也许你可以告诉我我需要学习什么?谢谢:)
  • 这是一个短的。您看到的错误与在容器中运行时出现的“错误”错误一致。如果容器没有足够大的 shm(共享内存空间),它会抛出同样的错误,误导人们修复不存在的问题。
  • 感谢您的解释!以后会注意的
猜你喜欢
  • 2013-11-16
  • 1970-01-01
  • 2021-12-09
  • 2013-11-01
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
  • 1970-01-01
相关资源
最近更新 更多