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

后端 未结 2 584
滥情空心
滥情空心 2020-12-21 03:14

I\'m trying to run headless chrome on Heroku with ruby. I\'ve installed the buildpacks https://github.com/heroku/heroku-buildpack-google-chrome/ and https://github.com/herok

2条回答
  •  隐瞒了意图╮
    2020-12-21 03:44

    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:

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

    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"
    

提交回复
热议问题