ruby – 在heroku上使用chrome驱动程序运行selenium:`找不到Chrome二进制文件

我是一个菜鸟,因为它涉及Linux设置(和heroku),所以如果这个问题是基本的道歉.

我想在Heroku上运行selenium webkit(在ruby中).我遇到一个困难,我的脚本无法找到Chrome二进制文件.

我实际上让chrome自己工作:

~ $chromedriver
Starting ChromeDriver 2.22.397932 (282ed7cf89cf0053b6542e0d0f039d4123bbb6ad) on port 9515
Only local connections are allowed.

chromedriver是我从/ app / vendor / bundle / bin / chromedriver复制的文件,只是为了让它变得更容易.存在chromedriver文件,因为我安装了chromedriver-helper gem. gem应该使二进制文件可用于ruby进程,但没有.

我也试过明确地设置路径,例如我的ruby代码中的Selenium :: WebDriver :: Chrome.driver_path =’chromedriver’,前面提到的文件位于根类别中.

它在本地完美运行(有或没有driver_path)

可能是什么原因?我从几年前开始阅读this SO thread,但它似乎已经过时了.任何想法将不胜感激!

错误跟踪:

~ $ruby bin/run.rb
/app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/response.rb:70:in `assert_ok': unknown error: cannot find Chrome binary (Selenium::WebDriver::Error::UnknownError)
  (Driver info: chromedriver=2.22.397932 (282ed7cf89cf0053b6542e0d0f039d4123bbb6ad),platform=Linux 3.13.0-91-generic x86_64)
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/default.rb:90:in `request'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:649:in `raw_execute'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:123:in `create_session'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:87:in `initialize'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/chrome/bridge.rb:48:in `initialize'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:64:in `new'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:64:in `for'
    from /app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver.rb:84:in `for'
    from /app/lib/mealpass_orderer.rb:12:in `initialize'
    from /app/lib/mealpass_orderer.rb:8:in `new'
    from /app/lib/mealpass_orderer.rb:8:in `run'
    from bin/run.rb:3:in `<main>'

更新:

我尝试使用AWS EC2服务器(启动实例,克隆git repo,安装所有依赖项).同样的事也发生在那里.也就是说,能够从终端执行chromedriver,但在运行脚本时看到相同的错误.

最佳答案
ChromeDriver只是Chrome的驱动程序.它需要安装在同一台机器上的实际Chrome浏览器才能实际运行.

Heroku默认情况下没有在其dynos上安装Chrome.您需要使用安装Chrome的buildpack.例如:

https://github.com/dwayhs/heroku-buildpack-chrome

您可以看到它如何获取Chrome:

https://github.com/dwayhs/heroku-buildpack-chrome/blob/master/bin/compile#L36-38

转载注明原文:ruby – 在heroku上使用chrome驱动程序运行selenium:`找不到Chrome二进制文件 - 代码日志