为什么Selenium Web Driver说服务不可用?

时间:2014-03-30 12:25:20

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

当我运行以下代码时:

require "selenium-webdriver"
require 'rubygems'
require 'watir-webdriver'

b = Watir::Browser.new :phantomjs
b.goto 'http://www.google.com'
puts b.title
b.close

显示以下错误:

/home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/http/common.rb:66:in `create_response': unexpected response, code=503, content-type="text/html" (Selenium::WebDriver::Error::WebDriverError)
<HTML><TITLE>503 Service Unavailable</TITLE>
<H1>503 Service Unavailable</H1>
Failed to connect to server <B>127.0.0.1</B></HTML>
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/bridge.rb:634:in `raw_execute'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/bridge.rb:99:in `create_session'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/phantomjs/bridge.rb:32:in `initialize'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/common/driver.rb:45:in `new'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver/common/driver.rb:45:in `for'
    from /home/jotsarup/.gem/gems/selenium-webdriver-2.41.0/lib/selenium/webdriver.rb:67:in `for'
    from /home/jotsarup/.gem/gems/watir-webdriver-0.6.8/lib/watir-webdriver/browser.rb:46:in `initialize'
    from test_phantom.rb:7:in `new'
    from test_phantom.rb:7:in `<main>'

phantomjs未连接。我也试过Firefox,结果是一样的。

2 个答案:

答案 0 :(得分:0)

根据“无法连接到服务器 127.0.0.1 ”,您似乎无法到达本地计算机外部127.0.0.1是您的环回地址(对于您的计算机)而且我有看到这个问题在过去出现防火墙时出现了。如果您所在的公司需要通过防火墙路由流量,我建议您查看是否有任何流量试图通过您的计算机进行流量传输。如果您不在需要防火墙的公司,那么我建议删除防火墙/代理进行测试。

答案 1 :(得分:0)

看起来你是PROXY的幕后推手。在启动服务器之前添加以下代码段:

ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
b = Watir::Browser.new :phantomjs