Using gem Watir in Heroku - cannot find Chrome binary

泪湿孤枕 提交于 2020-02-06 07:27:04

问题


I am trying to scrap data in Heroku with the gem Watir but I have the following problem :

Selenium::WebDriver::Error::UnknownError (unknown error: cannot find Chrome binary

2018-06-12T17:29:54.221948+00:00 app[web.1]:   (Driver info: chromedriver=2.40.565383 

I am using those 2 buildpackers :

  • https://github.com/heroku/heroku-buildpack-google-chrome
  • https://github.com/heroku/heroku-buildpack-chromedriver

I don't understand how to fix the path in my rails project. As following this doc : https://github.com/heroku/heroku-buildpack-google-chrome#selenium

It's seems that I have to add this path

/app/.apt/usr/bin/google-chrome

But I don't understand at all where I have to add this.

If someone have the solution :) Thank you !


回答1:


I finally find what's wrong !

The following answer by Anka is working for my case :

Ruby / Heroku Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9516

Add the 2 following buildpacks :

https://github.com/heroku/heroku-buildpack-chromedriver

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

Add the following information in the .env file :

GOOGLE_CHROME_SHIM = '/app/.apt/usr/bin/google-chrome'

Then call the Watir Browser as following :

opts = {
    headless: true
  }

  if (chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil))
    opts.merge!( options: {binary: chrome_bin})
  end 

browser = Watir::Browser.new :chrome, opts


来源:https://stackoverflow.com/questions/50822893/using-gem-watir-in-heroku-cannot-find-chrome-binary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!