SOLVED

Set download directory via WebDriver

Highlighted
New Contributor

I'm using Edge v81.0.416.64 to run Selenium Tests using the matching Edge WebDriver, however it does not seem to be possible to set a custom download directory using the "download.default_directory" user profile preference, used in Chrome. I know that there is the option to change the download directory using group policies (https://docs.microsoft.com/en-us/DeployEdge/microsoft-edge-policies#downloaddirectory), but this is no viable option for web tests.

 

Am I missing something/is there another way? Is this something planned for the future?

 

EDIT: Setting the "download.default_directory" user profile preference works in Edge v79.0.309.65.

4 Replies
Highlighted

@Marcel_Holle we made some changes to MSEdgeDriver in v 81 that seem to be impacting your tests. Can you share the code sample for how you create the driver() object?

 

-John

Highlighted

Hi @johnjansen ,

 

we're using Selenium 3.141.0.0 & ChromeDriver classes:
 

 

var edgeOptions = new EdgeOptions
                  {
                      BinaryLocation = BrowserBinaryPath
                  };

DisableSpecCompliance (edgeOptions); // force "w3c" capability to false
AdjustBrowserNameCapability (edgeOptions); // Set DriverOptions.BrowserName to "MicrosoftEdge" instead of "Chrome"

edgeOptions.AddArgument ($"user-data-dir={userDirectory}");

edgeOptions.AddArgument ("no-first-run");
edgeOptions.AddArgument ("force-device-scale-factor=1");

edgeOptions.AddUserProfilePreference ("safebrowsing.enabled", true);
edgeOptions.AddUserProfilePreference ("download.default_directory", DownloadDirectory);

var driverService = ChromeDriverService.CreateDefaultService (driverDirectory, driverExecutable);
driverService.EnableVerboseLogging = false;
driverService.LogPath = logPath;

var driver = new ChromeDriver (driverService, _extendedEdgeOptions, commandTimeout);
driver.Manage().Timeouts().AsynchronousJavaScript = asyncJavaScriptTimeout;

 

Highlighted
Best Response confirmed by Marcel_Holle (New Contributor)
Solution

@Marcel_Holle thanks for the code, that helps so much. The issue is because you are using ChromeDriver() which is not supported on Edge 81 and newer. We wrote a pretty cool tool to enable this to work more seamlessly here: https://github.com/microsoft/edge-selenium-tools

 

Basically, it is fully backward compatible with the old Edge browser as well as the new Edge browser to try to help people save time writing new tests.

 

-John

Highlighted

Hi@johnjansen 

thank you so much, using Microsoft.Edge.SeleniumTools solved our issue.