SOLVED

Adding Chome Extension to Edge 85 with Selenium Java

%3CLINGO-SUB%20id%3D%22lingo-sub-1699537%22%20slang%3D%22en-US%22%3EAdding%20Chome%20Extension%20to%20Edge%2085%20with%20Selenium%20Java%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1699537%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3E%26nbsp%3BI%26nbsp%3B%3C%2FSPAN%3Ewant%20to%20add%20chrome%20extension%20from%20Selenium%20Java%20to%20Newest%20Edge%20Version%20with%20msedgedriver.%3C%2FP%3E%3CP%3EBut%20when%20the%20browser%20instance%20opens%20the%20extension%20is%20not%20getting%20added%20and%20developer%20mode%20is%20not%26nbsp%3B%3CBR%20%2F%3Ei.%20Edge%20Developer%20mode%20gets%20turned%20off%20when%20new%20instance%20is%20opened.%3CBR%20%2F%3Eii.%20Allow%20extensions%20from%20other%20stores%20is%20also%20automatically%20turned%20off.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20different%20codes%20with%20seleenium%204.0%20alpha%206.0%20as%20well%20as%20with%20the%20stable%20versions.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Epublic%20static%20WebDriver%20ini()%20%7B%3C%2FP%3E%3CP%3ESystem.setProperty(%22webdriver.edge.driver%22%2C%20%22D%3A%5C%5CSeleniumTest%5C%5Cnew%5C%5Cmsedgedriver.exe%22)%3B%3CBR%20%2F%3EDesiredCapabilities%20desiredCapabilities%20%3D%20new%20DesiredCapabilities%20()%3B%3CBR%20%2F%3EEdgeOptions%20options%20%3D%20new%20EdgeOptions()%3B%3CBR%20%2F%3EArrayList%3CSTRING%3E%20extensionList%3Dnew%20ArrayList%3CSTRING%3E()%3B%3CBR%20%2F%3EString%20extensionLocation%3D%22C%3A%5C%5CProgram%20Files%20(x86)%5C%5CMicrosoft%5C%5CEdge%5C%5CApplication%5C%5C85.0.564.51%5C%5CExtensions%5C%5CCombinedExtension%22%3B%3CBR%20%2F%3EextensionList.add(extensionLocation)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eoptions.setCapability(%20%22disable-infobars%22%2C%20true)%3B%3CBR%20%2F%3Eoptions.setCapability(%22extensionPaths%22%2C%20extensionList)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eoptions.merge(desiredCapabilities)%3B%3CBR%20%2F%3EWebDriver%20driver%20%3D%20new%20EdgeDriver(options)%3B%3CBR%20%2F%3Ereturn%20driver%3B%3CBR%20%2F%3E%7D%3C%2FSTRING%3E%3C%2FSTRING%3E%3C%2FP%3E%3CP%3EThe%20above%20code%20works%20fine%20with%20edge%20legacy.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20different%20other%20answers%20i%20have%20tried%20most%20of%20them%20doesnt%20work.%3C%2FP%3E%3CP%3EI%20tried%20the%20below%20code%20too%3C%2FP%3E%3CPRE%3ESystem.setProperty(%22webdriver.edge.driver%22%2C%20%22%26lt%3BwindowsMsEdgeChromiumDriverPath%26gt%3B%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20final%20ChromeOptions%20chromeOptions%20%3D%20new%20ChromeOptions()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20chromeOptions.setBinary(%22C%3A%5C%5CProgram%20Files%20(x86)%5C%5CMicrosoft%5C%5CEdge%20Beta%5C%5CApplication%5C%5Cmsedge.exe%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20chromeOptions.setExperimentalOption(%22useAutomationExtension%22%2C%20false)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20chromeOptions.setExperimentalOption(%22excludeSwitches%22%2C%20Collections.singletonList(%22enable-automation%22))%3B%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20final%20EdgeOptions%20edgeOptions%20%3D%20new%20EdgeOptions().merge(chromeOptions)%3B%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20final%20WebDriver%20webDriver%20%3D%20new%20EdgeDriver(edgeOptions)%3B%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1699537%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EChromium%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EEdge%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eextension%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EJava%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESelenium%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1700793%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20Chome%20Extension%20to%20Edge%2085%20with%20Selenium%20Java%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1700793%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F318459%22%20target%3D%22_blank%22%3E%40johnjansen%3C%2FA%3E%26nbsp%3B%20and%26nbsp%3B%40%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F484598%22%20target%3D%22_blank%22%3Efawkes%3C%2FA%3E%3C%2FP%3E%3CP%3EThank%20you%26nbsp%3B%20for%20your%20reply.%20It%20worked%20fine%20and%20the%20extension%20is%20getting%20added%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1700171%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20Chome%20Extension%20to%20Edge%2085%20with%20Selenium%20Java%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1700171%22%20slang%3D%22en-US%22%3E%3CP%3Ethanks%20for%20tagging%20me%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F484598%22%20target%3D%22_blank%22%3E%40fawkes%3C%2FA%3E%26nbsp%3B.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F803508%22%20target%3D%22_blank%22%3E%40farisk2010%3C%2FA%3E%26nbsp%3B%2C%20I%20think%20you%20just%20have%20they%20syntax%20incorrect%20for%20enabling%20extensions%20via%20the%20current%20driver%20design%3A%3C%2FP%3E%0A%3CP%3Evar%20options%20%3D%20new%20EdgeOptions()%3B%20%3CBR%20%2F%3Eoptions.AddArguments(%22load-extension%3D%2Fpath%2Fto%2Fextension%22)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eso%20something%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Epublic%20static%20WebDriver%20ini()%20%7B%3CBR%20%2F%3ESystem.setProperty(%22webdriver.edge.driver%22%2C%20%22D%3A%5C%5CSeleniumTest%5C%5Cnew%5C%5Cmsedgedriver.exe%22)%3B%3CBR%20%2F%3EDesiredCapabilities%20desiredCapabilities%20%3D%20new%20DesiredCapabilities%20()%3B%3CBR%20%2F%3EEdgeOptions%20options%20%3D%20new%20EdgeOptions()%3B%3CBR%20%2F%3E%2F%2FArrayList%3CSTRING%3E%20extensionList%3Dnew%20ArrayList%3CSTRING%3E()%3B%3CBR%20%2F%3EString%20extensionLocation%3D%22C%3A%5C%5CProgram%20Files%20(x86)%5C%5CMicrosoft%5C%5CEdge%5C%5CApplication%5C%5C85.0.564.51%5C%5CExtensions%5C%5CCombinedExtension%22%3B%3CBR%20%2F%3E%2F%2FextensionList.add(extensionLocation)%3B%3C%2FSTRING%3E%3C%2FSTRING%3E%3C%2FP%3E%0A%3CP%3Eoptions.setCapability(%20%22disable-infobars%22%2C%20true)%3B%3CBR%20%2F%3Eoptions.setCapability(%22extensionPaths%22%2C%20extensionList)%3B%3CBR%20%2F%3Eoptions.AddArguments(%22load-extension%3D%22%20%2B%20extensionLocation)%3B%3C%2FP%3E%0A%3CP%3Eoptions.merge(desiredCapabilities)%3B%3CBR%20%2F%3EWebDriver%20driver%20%3D%20new%20EdgeDriver(options)%3B%3CBR%20%2F%3Ereturn%20driver%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1699979%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20Chome%20Extension%20to%20Edge%2085%20with%20Selenium%20Java%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1699979%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F803508%22%20target%3D%22_blank%22%3E%40farisk2010%3C%2FA%3E%26nbsp%3BThanks%20for%20letting%20us%20know%2C%20and%20welcome%20to%20the%20MSFT%20Edge%20Insider%20community!%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20believe%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F318459%22%20target%3D%22_blank%22%3E%40johnjansen%3C%2FA%3E%26nbsp%3Bhas%20done%20related%20webdriver%20work%20and%20might%20be%20able%20to%20help.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CI%3EFawkes%20(they%2Fthem)%3CBR%20%2F%3EProgram%20Manager%20%26amp%3B%20Community%20Manager%20-%20Microsoft%20Edge%3CI%3E%3C%2FI%3E%3C%2FI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

 I want to add chrome extension from Selenium Java to Newest Edge Version with msedgedriver.

But when the browser instance opens the extension is not getting added and developer mode is not 
i. Edge Developer mode gets turned off when new instance is opened.
ii. Allow extensions from other stores is also automatically turned off.

 

I tried different codes with seleenium 4.0 alpha 6.0 as well as with the stable versions.

 

 

public static WebDriver ini() {

System.setProperty("webdriver.edge.driver", "D:\\SeleniumTest\\new\\msedgedriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities ();
EdgeOptions options = new EdgeOptions();
ArrayList<String> extensionList=new ArrayList<String>();
String extensionLocation="C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\85.0.564.51\\Extensions\\CombinedExtension";
extensionList.add(extensionLocation);

options.setCapability( "disable-infobars", true);
options.setCapability("extensionPaths", extensionList);

options.merge(desiredCapabilities);
WebDriver driver = new EdgeDriver(options);
return driver;
}

The above code works fine with edge legacy.

 

 

 

Also different other answers i have tried most of them doesnt work.

I tried the below code too

System.setProperty("webdriver.edge.driver", "<windowsMsEdgeChromiumDriverPath>");
            final ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe");
            chromeOptions.setExperimentalOption("useAutomationExtension", false);
            chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));            
            final EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);            
            final WebDriver webDriver = new EdgeDriver(edgeOptions);
4 Replies
Highlighted

@farisk2010 Thanks for letting us know, and welcome to the MSFT Edge Insider community! 

 

I believe @johnjansen has done related webdriver work and might be able to help.

 

Fawkes (they/them)
Program Manager & Community Manager - Microsoft Edge

Highlighted
Best Response confirmed by fawkes (Microsoft)
Microsoft Verified Best Answer
Solution

thanks for tagging me, @fawkes .

 

@farisk2010 , I think you just have they syntax incorrect for enabling extensions via the current driver design:

var options = new EdgeOptions();
options.AddArguments("load-extension=/path/to/extension");

 

so something like this:

 

public static WebDriver ini() {
System.setProperty("webdriver.edge.driver", "D:\\SeleniumTest\\new\\msedgedriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities ();
EdgeOptions options = new EdgeOptions();
//ArrayList<String> extensionList=new ArrayList<String>();
String extensionLocation="C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\85.0.564.51\\Extensions\\CombinedExtension";
//extensionList.add(extensionLocation);

options.setCapability( "disable-infobars", true);
options.setCapability("extensionPaths", extensionList);
options.AddArguments("load-extension=" + extensionLocation);

options.merge(desiredCapabilities);
WebDriver driver = new EdgeDriver(options);
return driver;
}

Highlighted

@johnjansen  and @fawkes

Thank you  for your reply. It worked fine and the extension is getting added

Highlighted

@farisk2010 Excellent, we're glad to hear it! Best of luck with the extension.

 

Fawkes (they/them)
Program Manager & Community Manager - Microsoft Edge