1

I'm trying to run some selenium C# end-to-end tests on Edge Chromium browser. One of the tests does a download check, basically it downloads a xml file and check whether it exists in the downloaded location.

I'm using Microsoft.Edge.SeleniumTools EdgeOptions to construct options for the EdgeDriver.

But the issue right now is that Edge blocks downloads.

1

Tried different sorts of things but none of them worked.

Same issue can be solved on Chrome by disabling "safebrowsing" on UserProfilePreferences in ChromeOptions.

I know for a fact that SmartScreen does the blocking, if that is so is there any profile preference that I can use to disable SmartScreen ?

Or any other workaround to force download without the block would be very helpful.

stranger
  • 55
  • 9

1 Answers1

0

For testing purposes, I suggest you create HashMap objects and try to set Edge preferences like below.

static void Main(string[] args)
 {
            HashMap<String, Object> edgePrefs = new HashMap<String, Object>();
            edgePrefs.put("profile.default_content_settings.popups", 0);
            edgePrefs.put("profile.default_content_setting_values.notifications", 2);       
            edgePrefs.put("profile.default_content_setting_values.automatic_downloads" , 1);        
            edgePrefs.put("profile.content_settings.pattern_pairs.*,*.multiple-automatic-downloads",1);

            var options = new EdgeOptions();
            egdeOptions.setExperimentalOption("prefs",edgePrefs);
            options.UseChromium = true;
            options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";   // Here add the Edge browser exe path.
            var driver = new EdgeDriver(@"Edge_driver_path_here...", options); // Here modify the selenium web driver path.
            driver.Navigate().GoToUrl("http://website_URL_here..."); 
            driver.FindElementById("lnk1").Click();
          
}

If the issue persists then I suggest you set the default download directory like below.

options.AddUserProfilePreference("download.default_directory", @"D://Folder1");

See whether it help to download the file.

Deepak-MSFT
  • 8,111
  • 1
  • 6
  • 14
  • do you know what user profile preferences are available for Edge Chromium ? Any source I can look into find the acceptable user profile preferences ? – stranger Apr 21 '21 at 04:58
  • Does the above sample code work for you? I try to search for the Edge pref. list but did not get information specifically for the Edge browser. You can try to refer to these two pref lists for Chromium. [Profile_pref1](https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup#l977), [Profile_pref2](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc). Common prefs can work for the Edge browser. Edge may not fully support all the preferences that could be set due to potential internal differences between Chromium and Edge. – Deepak-MSFT Apr 21 '21 at 06:19
  • I tried it but I can't find setExperimentalOption on EdgeOptions from Selenium Tools. I'm working on Selenium 3.x version but did you try the above code on Selenium 4 ? For your reference I'm using EdgeOptions from https://github.com/microsoft/edge-selenium-tools – stranger Apr 21 '21 at 07:54
  • Just for testing purposes, could you please go to 'edge://settings/privacy' using the Edge browser and try to disable the Microsoft Defender Smart Screen. Then try to run your code. See whether it lets the file be downloaded. – Deepak-MSFT Apr 26 '21 at 07:35
  • I've done that but the problem is when selenium opens a new Edge browser for testing the permission gets enabled again :( – stranger Apr 27 '21 at 02:50
  • I suggest you try to launch the Edge browser with the specific profile in which you had disabled the Microsoft Defender Smart Screen. In that way, it will keep disabled when you launch the Edge browser using the Selenium. – Deepak-MSFT Apr 27 '21 at 05:20