2014-03-19 45 views
0

我想有一個的Watir非常簡單的腳本,並由於某種原因不能:的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 

有同樣的錯誤..

+0

「我無法達到它」 - 不確定你的意思。達到什麼? – jschorr

+2

這是你的代碼中的錯字? - _browser.window.last_不起作用。它需要_browser.windows.last_ ...此外,你得到的錯誤是什麼? –

+0

謝謝安倍,這是一個問題,但仍然無法正常工作。我改變了這一點,模擬了標籤上的點擊 - 不起作用。似乎我無法獲取任何數據或填充該彈出窗口中的任何字段。我嘗試了幾個browser.windows。<>技術..「最後」,「索引」和標題。非工作。 – Devaffair

回答

0

這看起來很像的Watir-webdriver的或硒的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項目提交bug可能是值得的。 https://github.com/watir/watir-webdriver

+0

這不就是處理新窗口的全部重點嗎?一旦打開它就可以處理一個?任何想法如何繞過這個問題?修復它甚至?另一個寶石? – Devaffair

+1

在我的腳本中,我處理打開所有時間的新窗口。這種特殊情況有些不尋常之處。不幸的是,我不知道更多。 –

+0

好的。我會試着看看我能否以不同的方式彈出窗口。謝謝。 – Devaffair