我尝试在 ruby Capybara 中注册 Selenium chrome 驱动程序。但不幸的是,我没有找到任何有关启用日志记录的信息。我使用了添加了 perfLoggingPrefs: {enableNetwork: true} 的选项,并遇到了我应该启用日志记录的问题。有谁知道如何在 Ruby/Capybara 中启用 ChromeDriver 的日志记录?现在这是我的代码:
Capybara.register_driver(:selenium_mobile) do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_emulation(device_name: 'iPhone X')
options.add_option(:perfLoggingPrefs, {enableNetwork: true})
p "Default Selenium driver is used"
cps = Selenium::WebDriver::Remote::Capabilities.chrome(
loggingPrefs: {browser: 'ALL'},
perfLoggingPrefs: {enableNetwork: true})
Capybara::Selenium::Driver.new(app, browser: :chrome,
desired_capabilities: cps, options:
options)
end
end
Run Code Online (Sandbox Code Playgroud)
另外,我尝试输入命令行参数,例如
options.add_argument('verbose')
options.add_argument('log-path=./tmp/chromedriver.log')
Run Code Online (Sandbox Code Playgroud)
无论如何我遇到问题:
Selenium::WebDriver::Error::InvalidArgumentError:无效参数:“firstMatch”的条目 0 从无效参数中无效:指定了 perfLoggingPrefs,但未启用性能日志记录
我读到可以启用 ChromeDriver 日志记录LoggingPreferences,但我找不到任何关于 Ruby 的提及。
有谁知道如何在注册 Selenium 驱动程序时在 Ruby/Capybara 中启用 ChromeDriver 日志记录?
ruby selenium capybara selenium-chromedriver selenium-webdriver