Adding chrome extension in Edge Release 85 with selenium

Faris Raheem 21 Reputation points
2020-09-22T07:10:02.207+00:00

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

But while i am using the same with msedgedriver in the latest edge its not working i.e
i. Edge Developer mode gets turned off when new instance is opened.
ii. Allow extensions from other stores is also automatically turned off.

I am able to add extension to the legacy Edge with MicrosoftWebDriver by the following code:

public static WebDriver ini() {

    System.setProperty("webdriver.edge.driver", "D:\\SeleniumTest\\new\\MicrosoftWebDriver.exe");


    DesiredCapabilities desiredCapabilities = new DesiredCapabilities ();
    EdgeOptions options = new EdgeOptions();
    ArrayList<String> extensionList=new ArrayList<String>();
    String extensionLocation="C:\\Users\\faris.raheem\\AppData\\Local\\Packages\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\LocalState\\CombinedExtension";
    extensionList.add(extensionLocation);

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

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


    return driver;    
}

Code changes when changed to msedgedriver :

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;  
}
Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,164 questions
0 comments No comments
{count} votes

Accepted answer
  1. Deepak-MSFT 2,191 Reputation points Microsoft Vendor
    2020-09-23T07:02:12.807+00:00

    I suggest you make a test with the sample code below may help you to add the extension to the Edge browser using Selenium Java code.

    I am using Edge 85.0.564.51 (Official build) (64-bit) for making this test and I am using CRX file of the Office extension in this sample code.

    Java code:

    public static void main(String[] args)   
     {                            
             System.setProperty("webdriver.edge.driver","\\msedgedriver.exe");     
             EdgeOptions op=new EdgeOptions();  
             op.addExtensions(new File(".....Path_for_extension_here.....\\Office.crx"));  
             DesiredCapabilities capabilities = new DesiredCapabilities();  
                capabilities.setCapability(EdgeOptions.CAPABILITY, op);  
                op.merge(capabilities);         
             WebDriver browser = new EdgeDriver(op);  
             browser.get("https://your_URL_here...");  
     }  
    

    Output:

    26775-147.gif

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

    ----------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Faris Raheem 21 Reputation points
    2020-09-23T10:51:16.68+00:00

    Thanks for the solution

    0 comments No comments