Run Selenium with Chrome Driver on Heroku: 'Cannot Find Chrome Binary'

run selenium with chrome driver on heroku: `cannot find Chrome binary`

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

Chrome binary not found on Heroku with Selenium for Ruby on Rails

I'm guessing you upgraded to the latest selenium-webdriver and chromedriver in the last few weeks. chromeOptions is no longer a valid key to pass, you can try changing it to goog:chromeOptions but you really should just be using an instance of the Selenium::WebDriver::Chrome::Options class

Capybara.register_driver :chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.binary = ...
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

Heroku: Unable to find chromedriver when using Selenium

The way to do it is:

  1. Add the buildpacks with

    heroku buildpacks:add https://github.com/heroku/heroku-buildpack-google-chrome
    heroku buildpacks:add https://github.com/heroku/heroku-buildpack-chromedriver
  2. Add the env vars GOOGLE_CHROME_BIN and GOOGLE_CHROME_SHIM in Heroku both with value /app/.apt/opt/google/chrome/chrome i.e.

    heroku config:set GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome
    heroku config:set GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome
  3. Use watir in the following way

    args = %w[--disable-infobars --headless window-size=1600,1200 --no-sandbox --disable-gpu]
    options = {
    binary: ENV['GOOGLE_CHROME_BIN'],
    prefs: { password_manager_enable: false, credentials_enable_service: false },
    args: args
    }
    @browser = Watir::Browser.new(:chrome, options: options)


Related Topics



Leave a reply



Submit