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.
- Go to the chrome web store and copy the link of the plugin you want
- I chose to get adblock https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom
- Go to http://chrome-extension-downloader.com/ and copy the full link from above and click download extension
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 = Selenium::WebDriver::Chrome::Profile.new 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
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