Selenium: How do I start Chrome with RailsPanel Extension loaded?

给你一囗甜甜゛ 提交于 2019-12-25 07:33:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!