问题
What is the right way to do this?
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
Also, --load-extension with switches worked, but there is little documentation on Chromedriver for it.
Capybara::Selenium::Driver.new( app, :browser => :chrome, http_client: client, :switches => ['--load-extension=' + extension_path] )
回答1:
I've never used the extensions feature so no guarantees, but a look at the selenium-webdriver source - https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/chrome/profile.rb#L38 - shows #add_extension and #add_encoded_extensions methods on the Chrome::Profile object, so you can try something like
profile = Selenium::WebDriver::Chrome::Profile.new()
profile.add_extension(extension_path)
Capybara::Selenium::Driver.new(app, browser: :chrome, http_client: client, profile: profile)
来源:https://stackoverflow.com/questions/41497049/selenium-how-do-i-start-chrome-with-railspanel-extension-loaded