Selenium open Chrome with extension

Source: Internet
Author: User

When the use case fails, the first response is to check whether the element positioning is correct and the extension that helps the positioning is essential, however, selenium usually opens a clean browser without extension. If the operation procedure is long, you have to manually execute it until that step checks the elements, which takes a long time, so how can we make it open a browser with extensions? Firefox is simple, and a lot of tutorials can be searched as a result, but I haven't seen chrome after searching for an hour. Now I have figured out a solution and recorded it for future reference.
First, go to c: \ Users (User) \ your computer name \ appdata \ Local \ google \ chrome \ User Data \ Default \ extensions, and open extensions, the folder in it is an extension that has been installed (remember to hide the folder on the computer first, otherwise it cannot be found) but the name is a bunch of unordered English letters that I don't understand, my solution is to find the corresponding plug-in version number one by one, find the version number in the chrome extensions option, and then package the plug-in you need: Open chrome settings, and open the extension program in it, select the developer mode. An ID will appear under the plug-in you install. This ID corresponds to the plug-in you want to package and then package the extension program, find the version number folder under the corresponding folder (or you can copy this folder to any place on your computer), that is, the folder inside the ID folder, and click package extension, the corresponding file with the suffix CRX and PEM will appear at the same level of the version number. This CRX file is What we need. After the preparation is complete, check the Code:

Chromeoptions Options = new chromeoptions (); options. addextensions (new file ("C: \ Users \ swang \ appdata \ Local \ google \ chrome \ userdata \ Default \ extensions \ ijaobnmmgonppmablhldddpfmgpklbfh \ 1.6.0 _ 0.crx ")); // Add the extension method to add the path of the CRX File

Driver = new chromedriver (options );
 

Selenium open Chrome with extension

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.