[英]Watir - Handling a new window
I'm trying to have a very simple script with Watir, and for some reason can't: 我正在尝试使用Watir创建一个非常简单的脚本,由于某种原因,它无法:
This should login to a website with Twitter. 这应该使用Twitter登录到网站。
browser = Watir::Browser.start 'http://www.12mass.com/'
browser.link(:class, 'priceLogin').click
sleep 2
browser.element(:class, 'loginTwitter').click
browser.windows.last.use do
browser.text_field(:id, 'username_or_email').click
browser.text_field(:id, 'username_or_email').set 'name'
browser.text_field(:id, 'password').set 'pass'
browser.button(:id, 'allow').click
end
I get to a point where a new window opens, but I can't reach it and fill the credentials... 我到达了一个新窗口打开的位置,但是我无法到达它并填写凭据...
Every now an then I get an error (in my log): `rescue in rbuf_fill'. 现在每隔一个,我就会收到一个错误(在我的日志中):`rescue in rbuf_fill'。 I already added: 我已经添加:
require 'net/http'
http = Net::HTTP.new(@host, @port)
http.read_timeout = 500
To my code, but I still get the error and can't log fill the credentials in the new window. 对于我的代码,但仍然出现错误,无法在新窗口中填写凭据。
Also, I tried this: 另外,我尝试了这个:
browser.windows.last.use
browser.element(:css, '[for="username_or_email"]').click
Had the same error.. 发生了同样的错误。
This is looking very much like a bug in Watir-webdriver or Selenium-webdriver. 这看起来非常像Watir-webdriver或Selenium-webdriver中的错误。
The failure occurs when we get to the line 当我们上线时会发生故障
browser.element(:class, 'loginTwitter').click
Just for my own edification I changed that line to read 只是为了我自己的教育,我将该行改为
browser.div(:class_name, 'logBtn loginTwitter').click
The error I get is the following: 我得到的错误如下:
/Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1294:in `request'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1287:in `block in request'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:746:in `start'
from /Users/abrahamheward/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/http.rb:1285:in `request'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/bridge.rb:634:in `raw_execute'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/bridge.rb:612:in `execute'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/remote/bridge.rb:369:in `clickElement'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/element.rb:54:in `click'
from /Users/abrahamheward/.rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:131:in `click'
from /Users/abrahamheward/Work/kuality-coeus/lib/kuality-coeus/data_objects/test.rb:10:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
My guess is that the appearance of the new window is somehow confusing Watir/Selenium. 我的猜测是,新窗口的出现使Watir / Selenium感到困惑。
It might be worthwhile to submit a bug to the Watir-webdriver project on github. 向GitHub上的Watir-webdriver项目提交错误可能是值得的。 https://github.com/watir/watir-webdriver https://github.com/watir/watir-webdriver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.