无法连接到chromedriver

我使用capybara和selenium测试我的rails项目。 当我执行测试脚本时,它有这样的错误

Selenium::WebDriver::Error::WebDriverError: Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= 

我谷歌如何使用谷歌浏览器作为测试浏览器而不是Firefox

但它发生其他错误喜欢

 Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver http://127.0.0.1:9515 

我有完全相同的问题。 对我有用的是使用“chromedriver-helper”gem。 我的gemfile的一部分看起来像这样:

 group :development, :test do gem 'rspec-rails' gem 'capybara' gem 'selenium-webdriver' gem 'chromedriver-helper' end 

在Mac OS上

它适用于watir-webdriver和Safari

 browser = Watir::Browser.new :safari 

如果您想使用Chrome,请确保已安装Chrome,此外还需要安装mac os开发人员工具

 xcode-select --install 

还可以用brew安装chromedriver

 brew install chromedriver 

在Linux上

我在我的暂存Ubuntu 12.04服务器上遇到了同样的错误,问题是我没有像这样安装chrome本身(具有超级用户权限):

 wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' apt-get update apt-get install google-chrome-stable 

安装chromedriver(使用适合您系统和版本的路径):

 wget http://chromedriver.storage.googleapis.com/2.7/chromedriver_linux64.zip unzip chromedriver_linux64.zip cp chromedriver /usr/local/bin chmod +x /usr/local/bin/chromedriver 

之后,我建议你在无头模式下使用watir-webdriver

 require 'watir-webdriver' require 'headless' headless = Headless.new headless.start browser = Watir::Browser.new :chrome browser.goto 'http://google.com' ... browser.close headless.destroy 

祝好运!

在Ubuntu 12.10上运行,我也有错误消息:

 unable to connect to chromedriver http://127.0.0.1:9515 

即使在我下载并正确安装后仍无法正常工作。 我甚至尝试过使用chromedriver-helper gem。 所以我手动运行chromedriver(/ usr / bin / chromedriver)并发现了两件事:

1)我对libnss3缺少包依赖,使用sudo apt-get install libnss3

2)chromedriver 2.9版(最新截至2014年2月)要求chrome>版本31,我有v25,使用sudo apt-get --only-upgrade install google-chrome-stable

mac osx 10.10 with jruby 1.7.12

 unable to connect to chromedriver http://127.0.0.1:9515 

发现了这个 – > https://code.google.com/p/selenium/issues/detail?id=6574#c3

 module Selenium module WebDriver module Chrome class Service alias_method :old_start, :start def start @process.io.stdout = Tempfile.new("chromdriver-output") old_start end end end end end 

mac osx 10.9.4,jruby 1.7.6,selenium-webdriver 2.42.0,brew install chromedriver – >安装2.10

 got unable to connect to chromedriver http://127.0.0.1:9515 (Selenium::WebDriver::Error::WebDriverError) 

发现了这个 – > https://code.google.com/p/selenium/issues/detail?id=6574#c3

我们修补了webdriver / chrome / service.rb来包含

 @process.io.stdout = Tempfile.new("chromdriver-output") before @process.start 

解决了这个问题 – 老鼠!

在OS X上? 用Brew? 错过了指示?

 $>> brew info chromedriver chromedriver: stable 2.20 ... ==> Caveats To have launchd start chromedriver at login: ln -sfv /usr/local/opt/chromedriver/*.plist ~/Library/LaunchAgents Then to load chromedriver now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.chromedriver.plist 

跟着他们:)为我工作。 也有助于打开chrome,它可能需要更新。

Ubuntu的14-04-64

无法连接到chromedriver 127.0.0.1:9515

 $ chromedriver -v ChromeDriver 2.33.506092 $ which chromedriver /usr/local/bin/chromedriver 

  wget -N http://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip unzip chromedriver_linux64.zip chmod +x chromedriver sudo mv -f chromedriver /usr/local/share/chromedriver sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver ___ Capybara.register_driver(:headless_chrome) do |app| capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( chromeOptions: { args: %w[headless disable-gpu --screen-size=1024x640] } ) Capybara::Selenium::Driver.new( app, browser: :chrome, desired_capabilities: capabilities ) end Capybara.javascript_driver = :headless_chrome Capybara.current_driver = :headless_chrome 

配置圈ci时我遇到了一些问题

  • 添加到Xvfb的Gemfile界面

gem 'headless', '~> 2.3.1'

  • 添加到spec / rails_spec.rb

if ENV['HEADLESS'] == 'on' require 'headless' headless = Headless.new headless.start end

所以HEADLESS=on bundle exec rspec运行你的rspec by HEADLESS=on bundle exec rspec

解决此问题的工作配置示例:

circle.yml

  • 重新安装Chrome
  • 安装ChromeDriver
  • 安装Selenium

以下是一本优秀的手册: https : //gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5

如果上述解决方案不起作用,请尝试创建另一个gemset并执行测试

 rvm gemset create  rvm gemset use  gem install bundler bundle install 

因为只要两个版本的selenium-webdriver之间存在冲突,就会发生此问题

这对我有用:

  • 更新chrome chromedriver-update 2.42
  • 检查版本chromedriver -v
  • 搜索Chromedriver哪个chromedriver
  • 去掉chromedriver rm which chromedriver
  • 删除Chromedriver并安装新的1-rm chromedriver并下载chromedriver 2-解压缩chromedriver_mac64 \(2).zip 3- echo $ APTH(检查可执行bin的路径)
    4- mv chromedriver / usr / local / bin(放入垃圾箱)