SOLVED

Set download directory via WebDriver

%3CLINGO-SUB%20id%3D%22lingo-sub-1340286%22%20slang%3D%22en-US%22%3ESet%20download%20directory%20via%20WebDriver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1340286%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20using%20Edge%20v81.0.416.64%20to%20run%20Selenium%20Tests%20using%20the%20matching%20Edge%20WebDriver%2C%20however%20it%20does%20not%20seem%20to%20be%20possible%20to%20set%20a%20custom%20download%20directory%20using%20the%20%22download.default_directory%22%20user%20profile%20preference%2C%20used%20in%20Chrome.%20I%20know%20that%20there%20is%20the%20option%20to%20change%20the%20download%20directory%20using%20group%20policies%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2FDeployEdge%2Fmicrosoft-edge-policies%23downloaddirectory%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2FDeployEdge%2Fmicrosoft-edge-policies%23downloaddirectory%3C%2FA%3E)%2C%20but%20this%20is%20no%20viable%20option%20for%20web%20tests.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20I%20missing%20something%2Fis%20there%20another%20way%3F%20Is%20this%20something%20planned%20for%20the%20future%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1344530%22%20slang%3D%22en-US%22%3ERe%3A%20Set%20download%20directory%20via%20WebDriver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1344530%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F638211%22%20target%3D%22_blank%22%3E%40Marcel_Holle%3C%2FA%3E%26nbsp%3Bwe%20made%20some%20changes%20to%20MSEdgeDriver%20in%20v%2081%20that%20seem%20to%20be%20impacting%20your%20tests.%20Can%20you%20share%20the%20code%20sample%20for%20how%20you%20create%20the%20driver()%20object%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E-John%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1346497%22%20slang%3D%22en-US%22%3ERe%3A%20Set%20download%20directory%20via%20WebDriver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1346497%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%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%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3Ewe're%26nbsp%3Busing%26nbsp%3BSelenium%26nbsp%3B3.141.0.0%26nbsp%3B%26amp%3B%26nbsp%3BChromeDriver%26nbsp%3Bclasses%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Evar%20edgeOptions%20%3D%20new%20EdgeOptions%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20BinaryLocation%20%3D%20BrowserBinaryPath%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%0ADisableSpecCompliance%20(edgeOptions)%3B%20%2F%2F%20force%20%22w3c%22%20capability%20to%20false%0AAdjustBrowserNameCapability%20(edgeOptions)%3B%20%2F%2F%20Set%20DriverOptions.BrowserName%20to%20%22MicrosoftEdge%22%20instead%20of%20%22Chrome%22%0A%0AedgeOptions.AddArgument%20(%24%22user-data-dir%3D%7BuserDirectory%7D%22)%3B%0A%0AedgeOptions.AddArgument%20(%22no-first-run%22)%3B%0AedgeOptions.AddArgument%20(%22force-device-scale-factor%3D1%22)%3B%0A%0AedgeOptions.AddUserProfilePreference%20(%22safebrowsing.enabled%22%2C%20true)%3B%0AedgeOptions.AddUserProfilePreference%20(%22download.default_directory%22%2C%20DownloadDirectory)%3B%0A%0Avar%20driverService%20%3D%20ChromeDriverService.CreateDefaultService%20(driverDirectory%2C%20driverExecutable)%3B%0AdriverService.EnableVerboseLogging%20%3D%20false%3B%0AdriverService.LogPath%20%3D%20logPath%3B%0A%0Avar%20driver%20%3D%20new%20ChromeDriver%20(driverService%2C%20_extendedEdgeOptions%2C%20commandTimeout)%3B%0Adriver.Manage().Timeouts().AsynchronousJavaScript%20%3D%20asyncJavaScriptTimeout%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1347747%22%20slang%3D%22en-US%22%3ERe%3A%20Set%20download%20directory%20via%20WebDriver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1347747%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F638211%22%20target%3D%22_blank%22%3E%40Marcel_Holle%3C%2FA%3E%26nbsp%3Bthanks%20for%20the%20code%2C%20that%20helps%20so%20much.%20The%20issue%20is%20because%20you%20are%20using%20ChromeDriver()%20which%20is%20not%20supported%20on%20Edge%2081%20and%20newer.%20We%20wrote%20a%20pretty%20cool%20tool%20to%20enable%20this%20to%20work%20more%20seamlessly%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fedge-selenium-tools%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmicrosoft%2Fedge-selenium-tools%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBasically%2C%20it%20is%20fully%20backward%20compatible%20with%20the%20old%20Edge%20browser%20as%20well%20as%20the%20new%20Edge%20browser%20to%20try%20to%20help%20people%20save%20time%20writing%20new%20tests.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E-John%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1357390%22%20slang%3D%22en-US%22%3ERe%3A%20Set%20download%20directory%20via%20WebDriver%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1357390%22%20slang%3D%22en-US%22%3E%3CP%3EHi%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%3C%2FP%3E%3CP%3Ethank%20you%20so%20much%2C%20using%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fedge-selenium-tools%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft.Edge.SeleniumTools%3C%2FA%3E%20solved%20our%20issue.%3C%2FP%3E%3C%2FLINGO-BODY%3E
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

@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

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;

 

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

Hi@johnjansen 

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