Chromium loading using selenium

All I want is to download the chrome extension from the online store. I am looking a lot to figure this out, but only found out that we can download the extension from the local machine. I'm really curious if Selena has the functionality to download an extension from an online store or from a URL.

Please let me know what can I try using selenium?

+10
source share
7 answers

I'm not sure why you are especially concerned with downloading from the web store and then installing in Chrome.

I found several steps to download chrome extensions:

-In a computer connected to the Internet, install the extension from the extension page: https://chrome.google.com/webstore/detail/
-Find the source code for the extension. In XP, this can be found at: C: \ Documents and Settings \\ Local Settings \ Application Data \ Google \ Chrome \ User Data \ Default \ Extensions \
-You should see the version folder (that is, "0.0.21_0"). Copy this folder and move it to the machine you want to install.
-Open chrome on a disconnected machine and go to the wrench β†’ Tools β†’ Extensions
-Click "+" next to the "Developer" mode to display the developer options
-Click "Package Extension ..." and select the version folder as the root directory. Leave the private key file blank. This will create the .crx file in the version folder along with the private key, as if you were a developer.

- Or -

1- Find the ID of the extension that interests you. When on the extension details page 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 identifier. You will be prompted to save the CRX file. Drag this file into the Chrome window and continue the 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

+14
source

I did this with Python in case anyone is looking.

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

 from selenium import webdriver from selenium.webdriver.chrome.options import Options options = webdriver.ChromeOptions() options.add_extension('./exampleOfExtensionDownloadedToFolder.crx') driver = webdriver.Chrome(chrome_options=options) driver.get('http://www.google.com') 
+7
source
  • Put the chrome exe in the document file if you want to follow this and have a successful result.

  • Download the GET CRX extension from Google.

  • Download the extension (i.e. mine - "DHS" for testing API Rest).

  • Go to the Chrome Web Store β†’ find the extension (the one you already downloaded) β†’ right click on it and press :: GET CRX
    (This should download the CRX file. For my case, the CRX file is "extension_1_2_5.crx")

  • Drop the CRX file in any Chrome window (this may cancel it, but do not worry).

  • Now create your test and run

     public static void openChromeExtension(){ System.setProperty("webdriver.chrome.driver", "/Users/[your local name]/Documents/chromedriver"); ChromeOptions options = new ChromeOptions(); options.addExtensions(new File("/Users/[your local name]/Documents/extension_1_2_5.crx")); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); ChromeDriver driver = new ChromeDriver(capabilities); System.out.println("Opening extension"); driver.get("chrome-extension://**aejoelaoggembcahagimdiliamlcdmfm**/dhc.html"); driver.navigate().refresh(); System.out.println("Refresh successfully"); } 

    // this is the extension URL, or you can get the identifier on chrome: // extensions / find the extension and copy the ID . However, the URL must be the extension URL.

+6
source

I don’t know why, but someone deleted their answer, which was correct. Here is the content (obtained from @parishodak):

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

This specific example is presented in Java.

+3
source
 using System.IO; using System.IO.Compression; public static class ChromeExtension { public static string Execute() { var ParentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; var DirectoryPath = ParentPath.FullName.Remove(ParentPath.FullName.IndexOf(ParentPath.Name)); string startPath = $"{DirectoryPath}\\Exchanger\\ChromeExtension"; string zipPath = $"{DirectoryPath}Exchanger\\Extension.zip"; if (System.IO.File.Exists(zipPath)) { System.IO.File.Delete(startPath); } ZipFile.CreateFromDirectory(startPath, zipPath); if (System.IO.File.Exists($"{DirectoryPath}\\Exchanger\\Extension.crx")) { System.IO.File.Delete($"{DirectoryPath}\\Exchanger\\Extension.crx"); } System.IO.File.Move(zipPath, $"{DirectoryPath}\\Exchanger\\Extension.crx"); return $"{DirectoryPath}\\Exchanger\\Extension.crx"; } } 

.... //// ....

 Used: var options = new ChromeOptions(); options.AddExtension(ChromeExtension.Execute()); ....////.... 
0
source

The above solutions, although technically sound, do not always work as intended, so I thought of a different way. Because many times I need a lot of things that are better to do manually, authentications, certain cookies, etc.

I use folders as profiles, I run:

 chrome_options = Options() chrome_options.add_argument("user-data-dir=selenium") driver = webdriver.Chrome(chrome_options=chrome_options) driver.get("www.google.com") 

Then I manually install the extensions and execute the logins that I need now, every time I start Webdriver with this folder, everything is there

 chrome_options = Options() chrome_options.add_argument("user-data-dir=selenium") driver = webdriver.Chrome(chrome_options=chrome_options) driver.get("www.google.com") #Now you can see the Extensions and the logins done are present 

The advantage is that you can use several folders with different settings and extensions without having to install and remove extensions, change settings, change logins, etc.

0
source

To automate Chrome extensions, you must use a desktop UI test solution. A clean web testing solution, such as Selenium, cannot automate browser add-ons because it does not have access to them.

  • Sikuli is a good option for automation. Screen scraping is available if you add Tesseract .

  • UI.Vision is another good tool that includes built-in screen cleaning (if you need to get text from the user interface). It runs directly in a web browser, see this forum post on how to automate the Chrome extension with it.

0
source

All Articles