Load chrome extension using selenium Load chrome extension using selenium selenium selenium

Load chrome extension using selenium


I am not sure why you are particular about downloading from Webstore and then install into Chrome.

I found some steps to download chrome extensions:

-With a computer connected to the internet, install the extension from the extension page: https://chrome.google.com/webstore/detail/
-Navigate to the extension source code. In XP this is found at: C:\Documents and Settings\\Local Settings\Application Data\Google\Chrome\User Data\Default\Extensions\
-You should see a version folder (ie. "0.0.21_0"). Copy this folder and move it on the machine you want to install on.
-Open up chrome on the disconnected machine and go to Wrench -> Tools -> Extensions
-Click the + next to Developer mode to display the developer options
-Click 'Pack extension...' and choose the version folder as the root directory. Leave the private key file blank. This will create a .crx file in the version folder along with a private key as if you were the developer.

--Or--

1- Find the ID of the extension you’re interested in. When on the details page of the extension, it will be something like : bfbmjmiodbnnpllbbbfblcplfjjepjdn after https://chrome.google.com/webstore/detail/

2- Paste this into any other browser (not Chrome): https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D~~~~%26uc

3- and replacing ~~~~ with the extension ID. You’ll be prompted to save a CRX file. Drag this file to a Chrome window and proceed with installation.

Source: https://productforums.google.com/forum/#!topic/chrome/g02KlhK12fU

Finally, use the downloaded .crx file in ChromeOptions to load the extension

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

Source: https://sites.google.com/a/chromium.org/chromedriver/extensions


I did this with Python in case anyone was looking.

All you have to do is download the .crx file (I used https://chrome-extension-downloader.com/) and save it somewhere that Python can access it. In my example, I imported it to the same folder as my Python script, to load exampleOfExtensionDownloadedToFolder.crx.

from selenium import webdriver from selenium.webdriver.chrome.options import Options options = webdriver.ChromeOptions()options.add_extension('./exampleOfExtensionDownloadedToFolder.crx')driver = webdriver.Chrome(options=options) driver.get('http://www.google.com')


Here is how to load a chrome extension into chrome Selenium Python

Date = 20-12-19
Chrome version = 79.0.3945.88

The new version of Chrome support crx.crx (crx3) and if you use crx it will throw an error.
If you are using chrome version 73 or above then only follow this step


1> Crate a crx3 file.

1. Go to Chrome web store and search you Extension, copy the link of the extension.Screen shot
2. Go to this site and paste the link and download crx file for your Chrome extension.
3. Go to this GitHub page and download the module which will convert your crx file to crx3 or crx.crx.
4. Now you have your crx.crx or (crx3) file


**2> Python Code to Add chrome extension in selenium**

1. Put your extension.crx.crx file in the same folder as your code or give the path
2. You can copy-paste this code and just change the file crx.crx name at `chrome_options.add_extension(' YOUR - EXTENSION - NAME ')`

import os    from selenium import webdriver    from selenium.webdriver.chrome.options import Options            executable_path = "/webdrivers"    os.environ["webdriver.chrome.driver"] = executable_path        chrome_options = Options()    chrome_options.add_extension('  YOUR - EXTIONTION  - NAME    ')        driver = webdriver.Chrome(chrome_options=chrome_options)    driver.get("http://stackoverflow.com")