Ruby/Heroku Selenium :: WebDriver ::错误:: WebDriver错误:无法连接到chromedriver 127.0.0.1:9516 [英] Ruby / Heroku Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9516
问题描述
我试图用红宝石在Heroku上运行无头铬.我已经安装了构建包 https://github.com/heroku/heroku-buildpack -google-chrome/和 https://github.com/heroku/heroku- buildpack-chromedriver 并已将Selenium driver_path设置到正确的位置(在将其设置为buildpack设置的GOOGLE_CHROME_BIN
变量后,我已经像设置Selenium驱动程序路径之前得到了cannot find Chrome binary
一样进行了检查.获取unable to connect to chromedriver
).
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/heroku/heroku-buildpack-chromedriver and have set the Selenium driver_path to the correct location (I've checked this as before setting the Selenium driver path I get cannot find Chrome binary
, after setting it to the GOOGLE_CHROME_BIN
variable set by the buildpack I get the unable to connect to chromedriver
).
当我尝试使用Watir::Browser.new :chrome
或Watir::Browser.new :chrome, headless:true
启动Selenium/Watir时,我会得到Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9516
When I try to start Selenium / Watir with Watir::Browser.new :chrome
or Watir::Browser.new :chrome, headless:true
I get Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9516
任何建议都值得赞赏
推荐答案
由于配置错误以及将正确的选项哈希传递给Watir::Browser.new
的组合,我们也遇到了同样的问题.我们正在使用watir (6.10.3)
,selenium-webdriver (~> 3.4, >= 3.4.1)
和ruby '2.4.0'
.
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'
.
为了使所有内容都能在Heroku上正常运行,我们添加了以下buildpack:
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
- https://github.com/heroku/heroku-buildpack-google-chrome
- https://github.com/heroku/heroku-buildpack-chromedriver
- heroku/ruby
要成功初始化浏览器,您需要将路径传递给options哈希内的chromedriver bin. heroku-buildpack-chromedriver为bin搜索路径提供环境变量GOOGLE_CHROME_SHIM
.最后,将在本地和Heroku上运行的代码如下所示:
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"
这篇关于Ruby/Heroku Selenium :: WebDriver ::错误:: WebDriver错误:无法连接到chromedriver 127.0.0.1:9516的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!