在heroku上使用chrome驱动程序运行selenium:`找不到Chrome二进制文件` [英] run selenium with chrome driver on heroku: `cannot find Chrome binary`

查看:972
本文介绍了在heroku上使用chrome驱动程序运行selenium:`找不到Chrome二进制文件`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想运行selenium webkit(in),因为它涉及到linux setup(和heroku),所以我很抱歉。红宝石)在Heroku上。我遇到了一个困难,我的脚本找不到Chrome二进制文件。



我实际上已经使用chrome自行工作:

 〜$ chromedriver 
在端口9515上启动ChromeDriver 2.22.397932(282ed7cf89cf0053b6542e0d0f039d4123bbb6ad)
只允许本地连接。

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



我也尝试明确设置路径,例如 Selenium :: WebDriver :: Chrome.driver_path ='chromedriver'在我的ruby代码中,上述文件位于根类别中。



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



什么是原因?我已阅读多年前的此SO线程,但对我来说似乎过时了。任何想法将不胜感激!



错误追踪:

 〜$ ruby​​ bin / run.rb 
/app/vendor/bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/response .rb:70:在`assert_ok'中:未知错误:无法找到Chrome二进制文件(Selenium :: WebDriver :: Error :: UnknownError)
(驱动程序信息: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:在`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:`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'$ b / b 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 / apps / vendor / build / /bundle/ruby/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:64:in`for'
from / app / ve ndor / bundle / ruby​​ / 2.2.0 / gems / selenium-webdriver-2.53.4 / lib / selenium / webdriver.rb:84:在'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>'

更新: strong>



我对AWS EC2服务器(已启动的实例,克隆的git repo,安装了所有依赖项)进行了相同的尝试。同样的情况也发生在那里。也就是说,能够从终端执行chromedriver,但在运行脚本时会看到同样的错误。 ChromeDriver只是一个驱动程序铬。它需要安装在同一台机器上的真正的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


I'm a noob as it comes to linux setup (and heroku), so apologies if this question is basic.

I want to run selenium webkit (in ruby) on Heroku. I face a difficulty that my script cannot find Chrome binary file.

I actually got chrome to work by itself:

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

chromedriver being a file that I copied from /app/vendor/bundle/bin/chromedriver, just to make it easier for now. chromedriver file there exists because I installed chromedriver-helper gem. The gem was supposed to make the binary file available for ruby processes but didn't.

I've also tried setting path explicitly, e.g. Selenium::WebDriver::Chrome.driver_path = 'chromedriver' in my ruby code, with the aforementioned file located in the root category.

It all works perfectly locally (with or without the driver_path)

What can be the cause? I've read this SO thread from years ago, but it seems outdated to me. Any ideas would be greatly appreciated!

error trace:

~ $ 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>'

UPDATE:

I tried the same with AWS EC2 server (launched instance, cloned git repo, installed all dependencies). The same happens there as well. That is, able to execute chromedriver from terminal, but seeing same error when run the script.

解决方案

ChromeDriver is just a driver for Chrome. It needs the actual Chrome browser installed on the same machine to actually work.

Heroku doesn't have Chrome installed on its dynos by default. You need to use a buildpack that installs Chrome. For example:

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

You can see how it fetches Chrome:

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

这篇关于在heroku上使用chrome驱动程序运行selenium:`找不到Chrome二进制文件`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆