LoginSignup
9
9

More than 5 years have passed since last update.

Selenium WebDriverでChromeをExtension付きで起動する

Posted at

Selenium WebDriverでChromeを起動するとまっさらな状態で起動します。
任意のExtensionをインストールした状態で起動する方法です。

なお2014/06現在、WindowsではExtensionのインストールはWeb Store経由でしかできなくなった模様。いまのところMac環境では大丈夫です。

require 'selenium-webdriver'

chrome_extensions = []

File.open("hoge.crx", "rb") do |file|
  chrome_extensions << Base64.encode64(file.read.chomp)
end

capabilities = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"extensions" => chrome_extensions})
driver = Selenium::WebDriver.for :chrome, desired_capabilities: capabilities

driver.navigate.to 'http://qiita.com/'
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9