PrasanthRV
PrasanthRV

Reputation: 21

Selenium - Edge (Chromium) browser - Direct option to set default download path

Is there a direct way to set default download path for the Edge (Chromium) browser like how we have for chrome,firefox browsers

Sample snippet (for chrome):

Map pref = new HashMap(); pref.put("download.default_directory", "Path to download");

ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", pref);

Upvotes: 2

Views: 7941

Answers (2)

Windom Wu
Windom Wu

Reputation: 11

Starting from selenium 4, there is no need to import Microsoft.Edge.SeleniumTools, the function in Microsoft.Edge.SeleniumTools had already been a part of selenium 4 edge options

Upvotes: 0

Deepak-MSFT
Deepak-MSFT

Reputation: 11365

Here I am assuming that you are using the latest stable version of the Edge Chromium browser.

I am showing you the example for C# project.

I suggest you add a reference to Microsoft.Edge.SeleniumTools

using Microsoft.Edge.SeleniumTools;

namespace selenium_IE_automation
{
    class Program
    {
        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://");                    // Here add the download path.
            var driver = new EdgeDriver(@"D:\D drive backup\selenium web drivers\edgedriver_win64 81.0.416.68", options); // Here add the selenium web driver path.
        }
    }
}

Output:

enter image description here

References:

  1. Set download directory via WebDriver
  2. Selenium Tools for Microsoft Edge

Note: If you are developing using any other language then you can try to convert the above code to that language to make it work.

Edit:

This is the example using the JAVA language. It uses Selenium 4.

This solution is tested with the MS Edge Chromium 81.0.416.72 version.

public class new_java_class {

        public static void main(String[] args) {


                  System.setProperty("webdriver.edge.driver","D:\\D drive backup\\selenium web drivers\\edgedriver_win64  81.0.416.72\\msedgedriver.exe");

                  Map<String, Object> prefs = new HashMap<String, Object>();

                  prefs.put("download.default_directory",
                  System.getProperty("user.dir") + File.separator + "externalFiles" + File.separator + "downloadFiles");

                  EdgeOptions op=new EdgeOptions();
                  op.setExperimentalOption("prefs", prefs);

                  WebDriver browser = new EdgeDriver(op);

                  browser.get("https://microsoft.com");

        }

}

Upvotes: 1

Related Questions