Ruby-on-rails 无法连接到 chromedriver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19978577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to connect to chromedriver
提问by tsinghan
I use capybara & selenium test my rails project. when i execute the test script,it's has errors likes this
我使用水豚和硒测试我的 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=
I google how to use Google Chrome as the testing browser instead of Firefox
我在谷歌搜索如何使用 Google Chrome 而不是 Firefox 作为测试浏览器
but it occurs other errors likes
但它会发生其他错误,例如
Selenium::WebDriver::Error::WebDriverError:
unable to connect to chromedriver http://127.0.0.1:9515
回答by Jeremy
I had the exact same issue. What worked for me was using the "chromedriver-helper" gem. Part of my gemfile looks like this:
我有完全相同的问题。对我有用的是使用“chromedriver-helper” gem。我的 gemfile 的一部分看起来像这样:
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
回答by Mikhail Chuprynski
On Mac OS
在 Mac 操作系统上
It works fine with watir-webdriver and Safari
它适用于 watir-webdriver 和 Safari
browser = Watir::Browser.new :safari
If you'd like to use Chrome, make sure that it is installed, plus you need to install mac os developer tools with
如果你想使用 Chrome,请确保它已安装,另外你需要安装 mac os 开发者工具
xcode-select --install
and also install chromedriver with brew
并使用 brew 安装 chromedriver
brew install chromedriver
On Linux
在 Linux 上
I had the same error on my staging Ubuntu 12.04 server and the problem was I didn't install chrome itself like this (with superuser permissions):
我在临时 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
Install chromedriver(use proper path for your system and version):
安装 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
After that I would recommend you to use watir-webdriver in headless mode
之后,我建议您在无头模式下使用 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
Good luck!
祝你好运!
回答by stuartpalmer
Running on Ubuntu 12.10, I also had the error message:
在 Ubuntu 12.10 上运行,我也有错误消息:
unable to connect to chromedriver http://127.0.0.1:9515
Wasn't working even after I downloaded it and installed it correctly. I even tried using the chromedriver-helper gem. So I ran chromedriver manually (/usr/bin/chromedriver) and found out 2 things:
即使在我下载并正确安装后也无法正常工作。我什至尝试使用 chromedriver-helper gem。所以我手动运行了 chromedriver (/usr/bin/chromedriver) 并发现了两件事:
1) I had a missing package dependency on libnss3 which was fixed using sudo apt-get install libnss3
1) 我缺少对 libnss3 的包依赖,它是使用修复的 sudo apt-get install libnss3
2) Version 2.9 of chromedriver (latest as of Feb 2014) requires chrome > version 31, and I had v25, which was fixed using sudo apt-get --only-upgrade install google-chrome-stable
2) chromedriver 2.9 版(2014 年 2 月最新)需要 chrome > 31 版,我有 v25,已使用修复 sudo apt-get --only-upgrade install google-chrome-stable
回答by Bill Sloane
mac osx 10.9.4, jruby 1.7.6, selenium-webdriver 2.42.0, brew install chromedriver -> installed 2.10
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)
found this-> https://code.google.com/p/selenium/issues/detail?id=6574#c3
找到这个-> https://code.google.com/p/selenium/issues/detail?id=6574#c3
We have patched webdriver/chrome/service.rb to contain
我们已修补 webdriver/chrome/service.rb 以包含
@process.io.stdout = Tempfile.new("chromdriver-output")
before @process.start
which SOLVED the issue - crikey!
这解决了这个问题 - crikey!
回答by Gaurav Shah
mac osx 10.10 with jruby 1.7.12
mac osx 10.10 与 jruby 1.7.12
unable to connect to chromedriver http://127.0.0.1:9515
found this-> https://code.google.com/p/selenium/issues/detail?id=6574#c3
找到这个-> 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
回答by Volte
On OS X? Using Brew? Missed the instructions?
在 OS X 上?使用酿造?错过了说明?
$>> 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
Follow them :) worked for me. Also helps to open chrome, it might need updating.
跟随他们:) 对我来说有效。也有助于打开 chrome,它可能需要更新。
回答by Alexey Strizhak
i had some issue when configurate circle ci
我在配置 circle ci 时遇到了一些问题
- add to Gemfile interface for Xvfb
- 添加到 Xvfb 的 Gemfile 接口
gem 'headless', '~> 2.3.1'
gem 'headless', '~> 2.3.1'
- add to spec/rails_spec.rb
- 添加到规范/rails_spec.rb
if ENV['HEADLESS'] == 'on'
require 'headless'
headless = Headless.new
headless.start
end
if ENV['HEADLESS'] == 'on'
require 'headless'
headless = Headless.new
headless.start
end
so run your rspec by
HEADLESS=on bundle exec rspec
所以运行你的rspec
HEADLESS=on bundle exec rspec
Example of the working configuration where this problem is solved:
解决此问题的工作配置示例:
circle.yml
圆.yml
- reinstall Chrome
- install ChromeDriver
- install Selenium
- 重新安装 Chrome
- 安装 ChromeDriver
- 安装硒
Here's an excellent manual how to do it: https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5
这是一个很好的操作手册:https: //gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5
回答by serhiy
ubuntu-14-04-x64
ubuntu-14-04-x64
unable to connect to chromedriver 127.0.0.1:9515
无法连接到 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
回答by vishal Singh
This worked for me:
这对我有用:
- Update chrome ? chromedriver-update 2.42
- Check Version ? chromedriver -v
- Search Chromedriver ? which chromedriver
- Remove chromedriver ? rm
which chromedriver - Remove Chromedriver and install new one ?
1- rm chromedriver and Download chromedriver
? 2- unzip chromedriver_mac64\ (2).zip
? 3- echo $APTH (Check your path for executable bin)
? 4- mv chromedriver /usr/local/bin (Place to the bin)
- 更新铬?chromedriver 更新 2.42
- 检查版本?chromedriver -v
- 搜索 Chrome 驱动程序?哪个 chromedriver
- 删除 chromedriver ?R M
which chromedriver - 删除 Chromedriver 并安装新的?1-rm chromedriver 和下载 chromedriver ? 2- 解压 chromedriver_mac64\ (2).zip ? 3- echo $APTH(检查可执行文件的路径)
?4- mv chromedriver /usr/local/bin(放置到 bin)
回答by Prashanth Sams
If the above solutions doesn't work, try creating another gemset and execute tests
如果上述解决方案不起作用,请尝试创建另一个 gemset 并执行测试
rvm gemset create <your_gemset_name>
rvm gemset use <your_gemset_name>
gem install bundler
bundle install
Because this issue usually happens whenever there are conflicts between two versions of selenium-webdriver
因为这个问题通常发生在两个版本的 selenium-webdriver 之间发生冲突时

