2012-02-16 62 views
1

得到了與webdriver的的Watir一個非常惱人的問題..的Watir /硒 - browser.goto不斷收到超時錯誤在Chrome和Firefox

我已經調試了一下,發現我總是在超時::錯誤簡單的@ browser.goto行,甚至我可以直觀地看到頁面已經完全加載...

這種情況是這樣的: 打開瀏覽器,轉到一個url,點擊幾個鏈接,然後突然在一個點,腳本停止繼續瀏覽,等待約30秒以上並拋出錯誤。 嘗試Chrome和FF:Chrome更糟糕,通常會觸發第二或第三個鏈接點擊;對於FF,有時需要10+頁面瀏覽...

投注有一些環境或可比性問題:

[email protected]:~$ uname -am 
Linux deskbox 3.0.0-12-generiC#20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux 
[email protected]:~$ ruby -v 
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux] 
[email protected]:~$ rails -v 
Rails 3.2.1 
[email protected]:~$ gem -v 
1.8.15 
[email protected]:~$ gem list|grep webdriver 
selenium-webdriver (2.12.0) 
watir-webdriver (0.5.3) 

能有人幫助呢?源代碼在這裏:

#!/usr/bin/env ruby 
require 'watir-webdriver' 
require 'pry' 

class Search 
    attr_accessor :browser, :company_url, :company_name 

    def initialize() 
     @browser = Watir::Browser.start 'http://www.google.com', :chrome 
    end 

    def visit_company_home_via_google(company) 
     @company_name = company 
     @browser.goto "http://www.google.com/search?q=#{company}" 
     link = @browser.div(:id=>'ires').link 
     return nil unless link.exists? 
     @browser.goto link.href 
     @company_url ||= @browser.url 
     @company_url 
    end 


    def logoff() 
     @browser.close if @browser 
    end 

end 
s = Search.new 
puts s.visit_company_home_via_google("github") 
puts s.visit_company_home_via_google("Mashable") 
puts s.visit_company_home_via_google("Barracuda Networks") 
s.logoff 

我的結果是這樣的:

[email protected]:~/cuda$ ./search.rb 
https://github.com/ 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error) 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill' 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil' 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:126:in `readline' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:2208:in `read_new' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1177:in `request' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1170:in `block in request' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:627:in `start' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1168:in `request' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/default.rb:81:in `response_for' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/default.rb:43:in `request' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/http/common.rb:39:in `call' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:450:in `raw_execute' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:428:in `execute' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/common/navigation.rb:14:in `to' 
    from /usr/local/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.3/lib/watir-webdriver/browser.rb:61:in `goto' 
    from ./search.rb:17:in `visit_company_home_via_google' 
    from ./search.rb:33:in `<main>' 

回答

1

我認爲有在Chromedriver一個錯誤,沒有正確返回URL。我有你的例子使用:

require 'watir-webdriver' 

class Search 
    attr_accessor :browser, :company_name 

    def initialize 
    @browser = Watir::Browser.start 'http://www.google.com', :chrome 
    end 

    def get_company_url(company, url=nil) 
    @company_name = company 
    @company_url = url 
    @browser.goto "http://www.google.com/search?q=#{company}" 
    link = @browser.div(:id=>'ires').link 
    return nil unless link.exists? 
    @company_url ||= @browser.driver.current_url 
    end 

    def logoff() 
    @browser.close if @browser 
    end 

end 

s = Search.new 
puts s.get_company_url 'Barracuda Networks' 
+0

謝謝,對不起,我的問題不是很清楚;我的目標不是要獲得這些網址,而是要求watir轉到頁面,然後訪問它並返回;現在,GitHub很好,但是當瀏覽時,Mashable和梭子魚網絡都會被凍結;如果發生同樣的事情,你們誰都可以在同一個環境下試用它。我試着用EC2上的另一臺機器,得到了同樣的問題......所以我就是這麼問的... – 2012-02-17 22:04:05