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

和自甴很熟 提交于 2019-11-29 14:35:35

We also had the same problem due to the combination of configuration errors and passing the correct options hash to Watir::Browser.new. We are using watir (6.10.3), selenium-webdriver (~> 3.4, >= 3.4.1) and ruby '2.4.0'.

To get everything working on Heroku we added the following buildpacks:

To successfully initialize the browser you need to pass the path to chromedriver bin within the options hash. heroku-buildpack-chromedriver provides an environment variable GOOGLE_CHROME_SHIM for the bin search path. At the end the code which will work locally and on Heroku looks like this:

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
browser.goto "your url"

If anyone else stumbles across this, there's a good example here: https://github.com/jormon/minimal-chrome-on-heroku

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