How to use a extension with chrome and selenium-webdriver

Get the extension

I thought this would be the easy part. Turns out that the new chrome web store only lets you install directly to chrome.


Create And Use a profile

  • After you download your crx file put it in the same repo as your test. Next create a chrome profile and use the add_extension method.
      profile =
      profile.add_extension(File.dirname(__FILE__) +"/chrome_extensions/adblock/AdBlock_v2.5.61.crx")
  • Now you can use the new profile to with a driver
      Selenium::WebDriver.for(:chrome,:profile => profile)

Trouble Shooting

  • be sure that your chromedriver is updated. I used 26.0.1383.0
  • chrome  26.0.1410.43
  • selenium-webdriver  2.31.0

One Comment

  1. spence says:

    this code is old, this is the right way to do it.

    Using chromdriver 2 (supported since selenium-webdriver 2.37):

    prefs = {
    :download => {
    :prompt_for_download => false,
    :default_directory => “/path/to/dir”

    driver = Selenium::WebDriver.for :chrome, :prefs => prefs