Ruby on rails Heroku/Rails上的Chromedriver:无法加载应用程序:Selenium::WebDriver::Error::WebDriverError:不是文件:"/usr/local/bin/chromedriver“;

Ruby on rails Heroku/Rails上的Chromedriver:无法加载应用程序:Selenium::WebDriver::Error::WebDriverError:不是文件:"/usr/local/bin/chromedriver“;,ruby-on-rails,selenium,selenium-webdriver,heroku,selenium-chromedriver,Ruby On Rails,Selenium,Selenium Webdriver,Heroku,Selenium Chromedriver,我在Heroku,RoR应用程序上运行Selenium时遇到上述错误 我已经添加了buildpack heroku buildpack google chrome和heroku buildpack chromedriver 然后添加配置变量 GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome 并在capybara设置中添加了以下代码:

我在Heroku,RoR应用程序上运行Selenium时遇到上述错误

我已经添加了buildpack heroku buildpack google chrome和heroku buildpack chromedriver

然后添加配置变量

GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome
GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome
并在capybara设置中添加了以下代码:

chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)

chrome_opts = chrome_bin ? { "chromeOptions" => { "binary" => chrome_bin } } : {}


Capybara.register_driver :chrome do |app|   Capybara::Selenium::Driver.new(
     app,
     browser: :chrome,
     desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts),   ) end

Capybara.javascript_driver = :chrome
如chrome链接上所述:

我是否需要为webdriver的位置设置另一个变量?如果是,如何进行?我如何分配它


感谢

我们能够通过以下方式在heroku rails应用程序上实现此功能:

1) 添加了buildpack heroku buildpack google chrome和heroku buildpack chromedriver

2) 把司机安置在轨道上

options = Selenium::WebDriver::Chrome::Options.new
if Rails.env.production?
  Selenium::WebDriver::Chrome.path = ENV["GOOGLE_CHROME_SHIM"]
end
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
@driver = Selenium::WebDriver.for :chrome, options: options

无需在heroku上设置任何环境变量,因为GOOGLE_CHROME_SHIM是由webdriver构建包自动设置的。

我也遇到了同样的问题。我的问题,你解决了吗?