Watir - 处理新窗口

时间:2014-03-19 18:01:20

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

我正在尝试使用Watir创建一个非常简单的脚本,由于某种原因不能:

这应该使用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

我到达了一个新窗口打开的位置,但我无法访问它并填写凭据......

现在每次都会出现错误(在我的日志中):`在rbuf_fill中救援'。 我已添加:

require 'net/http' 
http = Net::HTTP.new(@host, @port)
http.read_timeout = 500

到我的代码,但我仍然收到错误,无法在新窗口中记录填写凭据。

另外,我试过这个:

browser.windows.last.use
browser.element(:css, '[for="username_or_email"]').click

有同样的错误..

1 个答案:

答案 0 :(得分:0)

这看起来非常像Watir-webdriver或Selenium-webdriver中的错误。

当我们到达

行时发生故障
browser.element(:class, 'loginTwitter').click

仅仅为了我自己的启发,我将该行改为

browser.div(:class_name, 'logBtn loginTwitter').click

我得到的错误如下:

/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>'

我的猜测是,新窗口的出现让Watir / Selenium感到困惑。

将错误提交给github上的Watir-webdriver项目可能是值得的。 https://github.com/watir/watir-webdriver