Extensions installed on chrome browser missing when chrome browser instance is opened with Selenium chromeDriver

16,250

Solution 1

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.

Solution 2

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.

Solution 3

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);

Solution 4

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

Share:
16,250

Related videos on Youtube

navger
Author by

navger

Updated on September 16, 2022

Comments

  • navger
    navger over 1 year

    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

    • navger
      navger
      Does anyone need more info to help on this...??
  • navger
    navger almost 11 years
    hi luksch..!! i tried opening chromedriver with "--user-data={profile path}" but that doesn't work either.
  • luksch
    luksch almost 11 years
    what is not working? is there an error message? did you look here: chromium.org/user-experience/user-data-directory
  • Rob W
    Rob W over 10 years
    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.
  • Anton Krouglov
    Anton Krouglov almost 7 years
    Even with updated syntax - it is not working for me. options.AddExcludedArgument("disable-default-apps")
  • MonsterMMORPG
    MonsterMMORPG about 6 years
    @RobW load CRX gives me missing manifest file error. Also how do i get zip package of an extension?