Need to set the download directory Chromium Edge browser using Selenium

Viewed 5496

I am trying to set the download directory of the Chromium Edge browser for selenium during automation.

For Chrome I could achieve this using ChromeOptions like this: options.setExperimentalOption("download.default_directory", downloadFilepath);

I need to do the same for the Chromium Edge browser. How to download the files inside a customized folder, rather than the default Downloads folder in our system

2 Answers

If you are using the C# language then you can refer to the steps below.

(1) Download the Selenium.Webdriver and Microsoft.Edge.SeleniumTools using Nuget package manager.

enter image description here

(2) Sample code:

using Microsoft.Edge.SeleniumTools;

        static void Main(string[] args)
        {
            var options = new EdgeOptions();
            options.UseChromium = true;
            options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";   // Here add the Edge browser exe path.
            options.AddUserProfilePreference("download.default_directory", @"D://Folder1");             // Here modify the download path.
            var driver = new EdgeDriver(@"D:\selenium web drivers\edgedriver_win64 83.0.478.61\", options); // Here modify the selenium web driver path.
        }

If you are using the JAVA language then try to refer to the example below.

(1) Download and Add a reference to the Selenium-server-4.0.0-alpha-5.jar in your JAVA project.

enter image description here

(2) Sample code:

public static void main(String[] args) 
{       
    System.setProperty("webdriver.edge.driver","D:\\selenium web drivers\\edgedriver_win64 83.0.478.61\\msedgedriver.exe");                     
    Map<String, Object> prefs = new HashMap<String, Object>();                                                       
    prefs.put("download.default_directory","D:\\Folder1");                         
    EdgeOptions op=new EdgeOptions();
    op.setExperimentalOption("prefs", prefs);             
    WebDriver browser = new EdgeDriver(op);
    browser.get("https://microsoft.com");

}

You can try to modify the code as per your own requirements.

If you are using any other developing language then you can try to convert the above examples to that language that may help to achieve your requirement.

Python and Selenium with Edge Version 95.0.1020.30 I was able to define the download directory like this:

  1. In Edge Click on the Profile (icon: Circle with a person silhouette) and select the profile you use for testing. I set my profile like this: (But the Profile name in Edge remains 'Profile 2', I can't explain that!)

    edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.add_argument("profile-directory=Matt Tester 1")

  2. In the Menu under the three dots ... select "Settings"

  3. Click on the left menu item: "Downloads"

  4. The first item is "Location" Click on the "Change" button to set the path to your download folder.

Related