2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
Screenshot error, but continue to execute.
wrong number of arguments (given 0, expected 1)
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
visit in hook, after scenario +1s, @1s
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
我一直在使用下面的代码片段来启动与旧的“ selenium-webdriver” v3.6.0的会话,并收到上述错误:
6月23日更新。
if Capybara.default_driver == :selenium
Capybara.register_driver :selenium do |app|
# In the block, we build up an `options` hash to pass to
# Capybara::Selenium::Driver.new(app, options)
# which in turn calls
# Selenium::WebDriver.for(options[:browser], options)
browser = Configuration.fetch('browser.type', :firefox)
options = {
browser: browser, # chrome
}
if Configuration.fetch('options.webdriver.use_hub', false)
{...}
elsif browser == :firefox
{...}
elsif browser == :chrome
chrome_logpath = "../chromedriver.log"
options[:service] = ::Selenium::WebDriver::Service.chrome(
args: {
verbose: true,
log_path: chrome_logpath,
}
)
chrome_options = Selenium::WebDriver::Chrome::Options.new
chrome_options.add_argument("user-agent='QA Test'")
chrome_options.add_option('w3c',false)
options[:options] = chrome_options
end
Capybara::Selenium::Driver.new(app, options)
end
end
将该gem提升至v3.142.0之后,我得到了该错误。追溯到https://github.com/SeleniumHQ/selenium/blob/master/rb/CHANGES中的Selenium Webdriver Changelog,然后发现以下描述,这可能会破坏当前代码 3.141.592(2019-04-18)
Chrome:
Added support for instantiating service class directly and moved all driver executable configuration there (command-line arguments, port, etc.)
Passing driver_opts, driver_path and port to driver initializer is now deprecated
so use Selenium::WebDriver::Service.chrome instead,
which allows to customize executable behavior in similar way.
Once initialized, this object can be passed as :service keyword
during driver initialization.
* Deprecated Chrome.driver_path= in favor of Service::Chrome.driver_path=
谷歌搜索了一段时间,我发现了一些结果和解决方法,例如使用“ webdriver” gem,但是我不太喜欢它。
所以想知道我是否可以更改上面的代码片段以使其与3.142.0及更高版本的selenium-webdriver相适应?我目前正在使用Capybara v3.18.0。
谢谢大家
答案 0 :(得分:0)
这不是错误,而是弃用警告。告诉您在selenium-webdriver v4.0发布之前,您需要更改代码。如果您觉得必须今天更新代码,则类似
elsif browser == :chrome
options[:service] = ::Selenium::WebDriver::Service.chrome(
args: {
verbose: true,
log_path: "../chromedriver.log",
}
)
chrome_options = Selenium::WebDriver::Chrome::Options.new
# add user agent to that class options
chrome_options.add_argument("user-agent='QA Test'")
options[:options] = chrome_options
end
您显示的其他内容
Screenshot error, but continue to execute.
wrong number of arguments (given 0, expected 1)
有所不同,并非来自您显示的任何代码。