Heroku:使用Selenium时找不到chromedriver [英] Heroku: Unable to find chromedriver when using Selenium
问题描述
我有一个执行此操作的Ruby代码:
I have a Ruby code that does this:
browser = Watir::Browser.new(:chrome, switches: switches, headless: true)
browser.goto(....)
当我在Heroku上运行代码
When I run the code on Heroku I get
Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github
.com/SeleniumHQ/selenium/wiki/ChromeDriver.
我见过类似 Heroku:使用Watir / Selenium时无法连接到chromedriver 127.0.0.1:9515
,但我不知道如何正确配置buildpacks。我尝试过的
:
I've seen posts like Heroku: unable to connect to chromedriver 127.0.0.1:9515 when using Watir/Selenium but I don't know how to properly configure the buildpacks. I've tried with:
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-google-chrome
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-chromedriver
,但是当我尝试将更改推送到Heroku时,我得到:
but then when I try to push the changes to Heroku I get:
Error Plugin: chromedriver: files attribute must be specified in /Users/leticia/.local/share/heroku/node_modules/chromedriver/package.json
$ b $中指定files属性b
有人可以逐步指导我如何设置必要的buildpack,以使Watir gem在Heroku中工作吗?
Can someone give me a step by step on how to set the necessary buildpacks to make the Watir gem work in Heroku?
谢谢
更新:
我需要'webdrivers',现在我得到 Selenium :: WebDriver :: Error :: WebDriverError:无法连接到chromedriver 127.0.0.1:9515
。
I've required 'webdrivers' and now I'm getting Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
.
我已经尝试将环境变量配置为:
I've tried configuring the env vars to:
ENV['GOOGLE_CHROME_BIN'] = "/app/.apt/opt/google/chrome/chrome"
ENV['GOOGLE_CHROME_SHIM'] = "/app/.apt/usr/bin/google-chrome-stable"
并执行以下操作:
options = Selenium::WebDriver::Chrome::Options.new
chrome_bin_path = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
options.binary = chrome_bin_path if chrome_bin_path
options.add_argument('--headless')
driver = Selenium::WebDriver.for :chrome, options: options
,但最后还是出现错误线。
but I'm still getting the error in the last line.
更新2:
我搬到了Dokku而不是Heroku,我得到了同样的错误。 Selenium :: WebDriver :: Error :: WebDriverError:无法连接到chromedriver 127.0.0.1:9515
。
I moved to Dokku instead of Heroku and I get the same error. Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
.
推荐答案
方法是:
-
使用以下方法添加构建包
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
添加环境变量Heroku中的 GOOGLE_CHROME_BIN
和 GOOGLE_CHROME_SHIM
都具有值 /app/.apt/opt/google/ chrome / chrome
即
heroku config:set GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome
heroku config:set GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome
按以下方式使用watir
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)
这篇关于Heroku:使用Selenium时找不到chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!