Monday, August 27, 2018

Selenium : Loading Google Chrome Driver Amongst Extensions

| Monday, August 27, 2018
By default, Chrome driver browser instance opens alongside fresh profile when webdriver launch it. So your installed extensions inward google chrome browser volition non display inward google chrome driver browser instance when you lot run assay inward chrome driver. Now supposing at that spot is an extension(any xyz extension) which i wants to charge alongside google chrome driver when run your assay using selenium webdriver. Is is possible? How to charge google chrome driver browser event alongside extension? Yes nosotros tin lav produce it.. You involve to follow bellow given steps to load chrome driver alongside extension.

For example, i wants to load Page Ruler extension alongside google chrome driver event which is already installed inward my google chrome default browser. Way to charge whatsoever extension alongside google chrome driver is same. You tin lav charge whatsoever other extension also equally per your requirement. Earlier nosotros learnt how to charge firefox driver alongside improver inward THIS POST.

To charge whatsoever chrome extension alongside webdriver chrome driver instance, You involve .crx file. If you lot convey .crx file, you lot tin lav charge it real easily inward selenium webdriver chrome instance. Bellow given steps volition create .crx file of Page Ruler google chrome extension.

Get Extension ID
First of all you lot involve to acquire ID of extension.
For that,
  • Open google chrome browser.
  • Open URL : chrome://extensions/ inward chrome browser. It volition demonstrate you lot listing of installed extensions.
  • Tick developer trend depository fiscal establishment jibe box which is display at transcend correct corner of page.
  • It volition demonstrate you lot ID of each extension equally shown inward bellow image. Note downward the ID of Page Ruler extension which you lot wants to charge with google chrome driver event equally shown bellow.

Locate Chrome Extension Folder
First of all you lot involve to locate folder where your extension files are stored. Generally you lot volition acquire extension folder path using bellow given syntax.
  • Open Win Run dialog using keyboard Win + R keys.
  • Paste bellow given path in Run dialog and press enter.
%USERPROFILE%\Local Settings\Application Data\Google\Chrome\User Data\Default\Extensions

It volition opened upward folder where your all google chrome extensions are stored equally shown inward bellow image. Locate your extension folder together with opened upward it. You tin lav locate it using its ID, which is provided on google chrome's extension page equally shown inward bellow image.



  • Open that folder equally shown inward to a higher house image.
  • There volition live on around other folder alongside extension version number. Current version of page ruler extension is 2.0.9 then folder cite is display like 2.0.9_0. It volition live on dissimilar for other extensions.
  • Double click on extension's version folder to opened upward it. 
  • Copy amount path of extension's version folder together with glue it inward notepad. We volition role it inward side yesteryear side step.



So at ane time you lot convey amount path of your extension's version folder together with at ane time you lot tin lav pack extension real easily to create .crx file equally described inward bellow step.

Create .crx  file yesteryear packing extension
To pack extension

  • Navigate to google chrome extensions page.
  • Tick developer trend depository fiscal establishment jibe box.
  • Click on Pack extension button. It volition opened upward Pack extension dialog equally bellow.
  • Set Extension's version folder path(which is re-create during previous step) inward "Extension origin directory" text box of Pack extension dialog.
  • Click on Pack extension button.
  • It volition create .crx file inward your extension folder. .crx file path volition display on Pack extension dialog equally shown bellow. .crx file cite tin lav live on dissimilar equally per your extension version.


  • Go to folder where .crx file is located.
  • Copy 2.0.9_0.crx file inward our instance together with glue it in D: drive.
Now nosotros have 2.0.9_0.crx file inward D: campaign which nosotros tin lav role inward our selenium webdriver assay to charge extension alongside chrome driver instance.

Create WebDriver assay to charge chrome driver alongside extension
Now nosotros are create to launch chrome driver browser event alongside extension. Create bellow given assay inward eclipse together with run it.

chromeExtension.java
package SeleniumExcercise;  import java.io.File; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities;  world class chromeExtension {   WebDriver driver;   world static void main(String args[]) {    // Create object of ChromeOptions to charge chrome driver options.   ChromeOptions options = novel ChromeOptions();    // Load extension file from D: drive.   options.addExtensions(new File("D://2.0.9_0.crx"));    // Set chromedriver.exe path.   System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");    // Set browser capability to charge options alongside driver.   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability(ChromeOptions.CAPABILITY, options);    // Load chrome driver alongside extension.   ChromeDriver driver = novel ChromeDriver(capabilities);   driver.get("http://www.google.com");  } }

Above assay volition charge chrome driver alongside page ruler extension equally shown inward bellow image.


This means you lot tin lav charge whatsoever extension alongside chrome driver using .crx file.

Related Posts