Reputation: 740
I need to use Selenium to launch the Edge (Chromium) browser. I can do this without any problems.
However, I want to launch the said browser with an unpacked extension installed. I have the path for the extension. I'm able to do this in Chrome by adding an argument called --load-extentsion=<path>
in my ChromeOptions
. However, the same doesn't work for Edge Chromium.
Reading the docs for the MsEdgeDriver, I found this:
So, I tried to package the extension using this button shown in the image below:
And used the code below:
EdgeOptions edgeOptions = new EdgeOptions();
File extension = new File(extensionPath + File.separator + "my-extension.crx");
byte[] fileContent;
WebDriver webDriver;
try {
fileContent = Files.readAllBytes(extension.toPath());
edgeOptions.setCapability("extensions",Base64.getEncoder().encodeToString(fileContent));
webDriver = new EdgeDriver(edgeOptions);
} catch (IOException e) {
e.printStackTrace();
}
THe browser launches fine, but my extension is not loaded.
I need to be able to load an unpacked extension, without having to publish it on Chrome or Edge app stores.
Can anyone help me?
Thanks Sriram
Upvotes: 1
Views: 760
Reputation: 2230
You should add the extension like this:
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var extensionName = "3.1.3_0.crx";
var options = new EdgeOptions();
options.AddExtensionPath($@"{outPutDirectory}\{extensionName}");
Alternatively you can use the AddExtension(string pathToExtension)
Upvotes: 0