Watir - 超时:错误 - 忽略睡眠

时间:2015-01-05 15:47:52

标签: ruby selenium watir

问题:输入用户ID和密码后,我们的网站加载页面的速度很慢。为了抵消这种情况,除了wait_until_present方法之外,我还尝试输入“Sleep”语句。网页通常在大约70秒后加载,但是在60秒后我会超时。如果除了“wait_until_present”的默认60秒之外我还有90秒的睡眠声明,为什么会发生这种情况?

RB文件中的代码:

输入用户ID和密码

@browser.driver.find_element(id: "ctl00_ContentPlaceHolder1_Wizard1_txtUserName").send_keys ""
@browser.driver.find_element(name: "ctl00$$Wizard1$StartNavigationTemplateContainerID$btnNext").click
@browser.driver.find_element(id: "ctl00_ContentPlaceHolder1_Wizard1_txtPassword").send_keys ""
@browser.driver.find_element(name: "ctl00$$Wizard1$StepNavigationTemplateContainerID$btnNext").click

等到页面加载

sleep(90)
@browser.b(:text => "You are now viewing info for 1st Global House").wait_until_present

错误:

  

C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in rescue in rbuf_fill': Timeout::Error ( imeout::Error) from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in rbuf_fill'           来自C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in readuntil' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in readline'           来自C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2563:in read_status_line' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2552:in read_new'           来自C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1320:in block in transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1317:in catch'           来自C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1317:in transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1294:in request'           来自C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1287:在block in request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:746:in开始'           来自C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1285:request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/ ebdriver/remote/http/default.rb:83:in response_for'           来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/   ebdriver / remote / http / default.rb:39:in request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/ ebdriver/remote/http/common.rb:40:in call'           来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/   ebdriver / remote / bridge.rb:640:在raw_execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/ ebdriver/remote/bridge.rb:618:in执行'           来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/   ebdriver / remote / bridge.rb:375:在clickElement' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/ ebdriver/common/element.rb:54:in点击'           来自createaccount.rb:40:在''

1 个答案:

答案 0 :(得分:0)

根据Ruby Bindings页面,Ruby标准库中的Net :: HTTP类在驱动程序调用之间的默认超时为60秒。您可以根据this answer增加此超时。