一尘不染

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

selenium

对于Linux设置(和heroku),我是一个菜鸟,如果这个问题很简单,我们深表歉意。

我想在Heroku上运行Selenium Webkit(红宝石)。我遇到了一个困难,我的脚本无法找到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
。这本宝石原本应该使二进制文件可用于红宝石处理,但事实并非如此。

我还尝试了显式设置路径,例如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: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服务器上尝试了相同的方式(启动实例,克隆的gitrepo,安装了所有依赖项)。那里也发生同样的情况。也就是说,能够从终端执行chromedriver,但是在运行脚本时看到相同的错误。


阅读 315

收藏
2020-06-26

共1个答案

一尘不染

ChromeDriver只是Chrome的驱动程序。它需要实际安装在同一台计算机上的实际Chrome浏览器。

Heroku默认未在其测功机上安装Chrome。您需要使用安装Chrome的buildpack。例如:

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

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

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

2020-06-26