这样做的正确方法是什么?
Capybara.register_driver :chrome do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
extension_path = '/Users/jill/Documents/rails_panel-master/rails_panel'
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => ['--load-extension=' + extension_path]})
Capybara::Selenium::Driver.new(app, :browser => :chrome, http_client: client, desired_capabilities: caps )
end
此外,带有开关的 - load-extension 工作正常,但Chromedriver上的文档很少。
Capybara::Selenium::Driver.new( app, :browser => :chrome, http_client: client, :switches => ['--load-extension=' + extension_path] )
答案 0 :(得分:1)
我从未使用过扩展功能,因此无法保证,但查看selenium-webdriver源代码 - https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/chrome/profile.rb#L38 - 会在Chrome :: Profile对象上显示#add_extension和#add_encoded_extensions方法,所以你可以尝试像
这样的东西profile = Selenium::WebDriver::Chrome::Profile.new()
profile.add_extension(extension_path)
Capybara::Selenium::Driver.new(app, browser: :chrome, http_client: client, profile: profile)