9

I have a peculiar problem here. When I open chromeBrowser via chromeDriver the extensions that were previously installed are missing.Also the apps extension is getting deleted from extensions folder(AppData\Local\Google\Chrome\User Data\Default\Extensions).

Now when I open the chrome browser manually, the extension appear on the browser , also the apps folder in extensions folder (AppData\Local\Google\Chrome\User Data\Default\Extensions) no w appears back.

Below is version of chromedriver & browser. chromedriver version :26.0.1383.0 chromebrowser : 26.0.1410.64

Cœur
  • 37,241
  • 25
  • 195
  • 267
navger
  • 133
  • 1
  • 1
  • 9

4 Answers4

9

You have to install each extension you want to use. In Selenium2 C# API it looks like this

var options = new ChromeOptions();
options.AddExtension(Path.GetFullPath("local/path/to/extension.crx"));
var driver = new ChromeDriver(options);

and the extension will be in the browser. Reference for java can be found here. See this question for how to obtain the .crx file for your extension from the chrome store.

Community
  • 1
  • 1
craastad
  • 6,222
  • 5
  • 32
  • 46
  • It does not need to be a CRX file, zip files are also accepted. The API is implemented as "Create a new user profile, unpack the extension and load the unpacked extension". Nevertheless +1, because this answer is more correct than the other one. – Rob W Sep 24 '13 at 16:40
  • @RobW load CRX gives me missing manifest file error. Also how do i get zip package of an extension? – Furkan Gözükara Feb 26 '18 at 08:11
5

this answer can be found here https://sites.google.com/a/chromium.org/chromedriver/extensions. Chrome extensions can be either packed or unpacked. Packed extensions are a single file with a .crx extension. Unpacked extensions are a directory containing the extension, including a manifest.json file.

To pack an unpacked extension, use the Pack button in chrome://extensions or use Chrome: "chrome.exe --pack-extension=C:\path\to\unpacked\extension --pack-extension-key=C:\myext.pem". See the extensions docs for other ways to do this that are more automation friendly. To unpack a packed extension, just unzip the file (you may need to rename the file from .crx to .zip for your zip utility to recognize it). Installing extensions via ChromeDriver

Packed (.crx file)

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Unpacked (directory)

ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=/path/to/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
Kevin Do
  • 51
  • 1
  • 2
2

If you want to have the extension available during testing you need to start chrome with a profile that defines this extension or give the extension as desired property to the webdriver. Usually, when you start chrome via webdriver the chrome starts with a fresh profile each time.

so if you want to load an extension in the test chrome, do this:

 DesiredCapabilities capabilities = DesiredCapabilities.chrome();
 capabilities.setCapability("chrome.switches", 
    Arrays.asList("--load-extension=/path/to/extension/directory"));
 WebDriver driver = new ChromeDriver(capabilities);

More info about the matter can be found here

luksch
  • 11,497
  • 6
  • 38
  • 53
  • hi luksch..!! i tried opening chromedriver with "--user-data={profile path}" but that doesn't work either. – navger May 14 '13 at 22:18
  • what is not working? is there an error message? did you look here: http://www.chromium.org/user-experience/user-data-directory – luksch May 15 '13 at 09:52
0

ChromeOptions options = new ChromeOptions(); options.AddAdditionalCapability("excludeSwitches", new object[] { "disable-default-apps" });
IWebDriver drv = new ChromeDriver(options);

available from webdriver .net bindings 2.40 onwards.

navger
  • 133
  • 1
  • 1
  • 9