Ruby:Chrome浏览器无法启动

时间:2019-12-19 10:04:48

标签: ruby selenium automation capybara webdrivers-gem

最近我已经安装了gem 'webdrivers', '~> 4.0'并尝试启动Chrome浏览器。但这不起作用。

代码

@app = Driver.new(Capybara::Session.new(:selenium_chrome))
Webdrivers::Chromedriver.current_version

错误日志

An error occurred while loading ./spec/login_spec.rb.
Failure/Error: require_relative '../pages/nav_bar.rb'

SyntaxError:
  /Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:83: syntax error, unexpected '.'
  ....VersionInfo.ProductVersion")&.strip
  ...                               ^
  /Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:87: syntax error, unexpected '.'
          System.call(location, '--product-version')&.strip
                                                      ^
  /Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:91: syntax error, unexpected '.'
          System.call(location, '--version')&.strip

1 个答案:

答案 0 :(得分:0)

正如评论中的Marek一样,gem使用的safe navigation operator仅在Ruby 2.3及更高版本中可用。升级到Ruby 2.3或将网络驱动程序降级到3.9.4,例如gem 'webdrivers', '~> 4.0'

我翻阅了code for 3.9.4,他们似乎并没有使用安全的导航操作符,因此值得一试。