How to load an extension in Edge using Selenium?

3.1k views Asked by At

I want to load an extension in Edge while using Selenium in C#. I have figured I have to use EdgeOptions.AddExtensionPath() but when passing the path no extensions are loaded.

The extension was extracted from %localappdata%\Microsoft\Edge\User Data\Default\Extensions

Here is the part of the code used to initialize the EdgeDriver:

using OpenQA.Selenium.Edge;

public void InitializeNewDriver() {
    string microsoftWebDriverPath = @"some\path";

    EdgeDriverService service = EdgeDriverService.CreateDefaultService(microsoftWebDriverPath);

    EdgeOptions options = new EdgeOptions();
    options.AddExtensionPath(@"path\to\extension\folder");

    Driver = new EdgeDriver(service, options);
}

Edit: I'm using Selenium.Webdriver v4.0.0

1

There are 1 answers

1
Deepak-MSFT On BEST ANSWER

I try to test the issue and found that if you pass the location of the extension to the options.AddExtensionPath() then the extension is not getting a load.

I suggest trying to use the options.AddExtensions() method and pass the .CRX file of the extension as a parameter.

It can help you to load the extension successfully.

C# code example:

var options = new EdgeOptions();
options.UseChromium = true;
options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
options.AddExtensions(@"Path_of_the_extension_here\extension.crx");
var driver = new Microsoft.Edge.SeleniumTools.EdgeDriver(@"Web_driver_path_here......", options);
driver.Navigate().GoToUrl("https://Your_URL_will_be_here...");

Output:

enter image description here

Further, you can modify the code sample as per your own requirements.