我正在尝试在Ubuntu 10.04上运行Watir for Ruby。我在我的(无显示屏)服务器上安装了Chrome和ChromeDriver,并安装了selenium-webdriver Gem。但是当我尝试在Watir中创建一个浏览器时,我得到了:
$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'watir-webdriver'
=> true
irb(main):003:0> browser = Watir::Browser.new :chrome
NoMethodError: undefined method `closed?' for nil:NilClass
from /usr/lib/ruby/1.8/net/http.rb:1060:in `request'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:92:in `create_session'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/chrome/bridge.rb:29:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/driver.rb:37:in `new'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/driver.rb:37:in `for'
from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver.rb:65:in `for'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.5.5/lib/watir-webdriver/browser.rb:35:in `initialize'
from (irb):3:in `new'
from (irb):3
from :0
irb(main):004:0>
在“Watir :: Browser.new”调用之后长时间暂停,我假设某种超时?也许想和Chromedriver谈谈?我正在运行相关Gems的这些版本:
$ gem list
*** LOCAL GEMS ***
addressable (2.3.2)
childprocess (0.3.6)
fastercsv (1.5.5)
ffi (1.2.0, 1.0.11)
libwebsocket (0.1.3)
multi_json (1.3.7, 1.0.4)
rubygems-update (1.8.24)
rubyzip (0.9.9)
selenium-webdriver (2.26.0, 2.18.0)
watir-webdriver (0.5.5)
websocket (1.0.3)
yajl-ruby (1.1.0)
答案 0 :(得分:1)
我正在尝试运行Chrome无头,我没有运行X服务器。 Xvfb做了这个伎俩,我现在正在努力:
http://en.wikipedia.org/wiki/Xvfb
http://blog.kagesenshi.org/2007/06/running-x-applications-headless-using.html