【问题标题】:unable to connect to chromedriver无法连接到chromedriver
【发布时间】:2013-11-14 13:13:29
【问题描述】:

我使用 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=

我谷歌how to use Google Chrome as the testing browser instead of Firefox

但它会发生其他错误,例如

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

【问题讨论】:

  • 你有什么版本的 Firefox 和 Chrome?它们究竟安装在哪里?
  • 我通过brew安装了firefox,firefox的版本是“firefox:21.0”
  • 您可以发布您的 gemfile 以及您的黄瓜 env 文件吗?

标签: ruby-on-rails selenium


【解决方案1】:

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

group :development, :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'webdrivers'
end

【讨论】:

  • selenium-webdriver 3.8.0更新为3.9.0后首次出现错误。添加chromedriver-helper gem 解决了问题
  • 注意:chromedriver-helper 自 2019-03-31 起已弃用,请更新以改用“webdrivers”gem。见github.com/flavorjones/chromedriver-helper
【解决方案2】:

在 Mac 操作系统上

它适用于 watir-webdriver 和 Safari

browser = Watir::Browser.new :safari

如果你想使用 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

祝你好运!

【讨论】:

  • 这与在 capybara 中运行测试有什么关系? watir-webdriver 完全是一个不同的框架......
【解决方案3】:

在 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 修复了这个问题

【讨论】:

    【解决方案4】:

    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
    

    解决了这个问题 - crikey!

    【讨论】:

      【解决方案5】:

      mac osx 10.10 和 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
      

      【讨论】:

      • 感谢您的回答。我只是将其更改为 @process.io.stderr = 以获得有用的错误消息。
      【解决方案6】:

      在 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,它可能需要更新。

      【讨论】:

      • 如果它可以帮助其他人,对我来说恰恰相反——我必须不​​让它运行(我必须找到进程并杀死它),我必须删除一些其他二进制文件/我用 which chromedriver 找到的垫片,直到它只是安装了 brew 的垫片(我的是 /usr/local/bin/chromedriver),然后再次运行我的测试,这次他们工作了!
      【解决方案7】:

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

      • 为 Xvfb 添加到 Gemfile 接口

      gem 'headless', '~> 2.3.1'

      • 添加到 spec/rails_spec.rb

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

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

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

      circle.yml

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

      这是一本很好的手册: https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5

      【讨论】:

      • 至于firefox报错——只需要安装firefox:sudo apt-get install firefox
      【解决方案8】:

      ubuntu-14-04-x64

      无法连接到 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
      

      【讨论】:

        【解决方案9】:

        这对我有用:

        • 更新 chrome chromedriver-update 2.42
        • 检查版本 chromedriver -v
        • 搜索 Chromedriver which 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 (放置到bin)

        【讨论】:

          【解决方案10】:

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

          rvm gemset create <your_gemset_name>
          rvm gemset use <your_gemset_name>
          gem install bundler
          bundle install
          

          因为这个问题通常发生在 selenium-webdriver 的两个版本之间存在冲突时

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-04-24
            • 2018-06-18
            • 2014-07-16
            • 1970-01-01
            • 2018-04-29
            相关资源
            最近更新 更多