While running selenium, I need to load a chrome extension from the web store. In my research, I only found how to load an extension from the local machine.
Is it possible for selenium to load an extension from the Web Store?
We can use extensions with Selenium webdriver in Python. We can have multiple extensions of the Chrome browser while we manually open the browser and work on it. However, while the Chrome browser is opened through Selenium webdriver, those extensions which are available to the local browser will not be present.
To add this extension to the Chrome browser, once it is launched by Selenium webdriver, we have to use the ChromeOptions class. We shall create an object of this class and apply addExtensions method on it. The path of the . crx file of the extension that we want to add is passed as a parameter to that method.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With