未初始化的常量Selenium :: WebDriver :: Chrome :: Options(NameError)

时间:2017-09-19 12:24:30

标签: ruby google-chrome selenium capybara

需要执行以下代码集。请参考我的代码:

Capybara.register_driver :logging_selenium_chrome do |app|
  caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs:
  {browser: 'ALL'})
  browser_options = ::Selenium::WebDriver::Chrome::Options.new()
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: 
  browser_options, desired_capabilities: caps)
end

但继续

  

未初始化的常量Selenium :: WebDriver :: Chrome :: Options(NameError)

任何人都知道可能导致这种情况的原因!!!

2 个答案:

答案 0 :(得分:3)

在selenium-webdriver 3.4.1中添加了

::Selenium::WebDriver::Chrome::Options - 升级到最新的selenium-webdriver gem(当前为3.5.2)

答案 1 :(得分:1)

您似乎需要Capybara声明browser_options。见下文:

Capybara.register_driver :logging_selenium_chrome do |app|
  caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs:
  {browser: 'ALL'})
  browser_options = Capybara::Selenium::WebDriver::Chrome::Options.new()
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: 
  browser_options, desired_capabilities: caps)
end