How to disable 'This type of file can harm your computer' pop up

后端 未结 8 1658
时光取名叫无心
时光取名叫无心 2020-11-27 20:43

I\'m using selenium chromedriver for automating web application. In my application, I need to download xml files. But when I download xml file, I get \'This type of file can

8条回答
  •  执念已碎
    2020-11-27 21:21

    I used all of suggested chrome options in C# and only when my internet connected worked for me but when internet disconnected none of them work for me. (I'm not sure.may be chrome safebrowsing need to internet connection)

    By using older version of chrome(version71) and chromedriver(version 2.46) and after downloading,i saw downloaded XML file name constains 'Unconfirmed' with 'crdownload' extension and parsing XML file wouldn't work properly. Finally, creating wait with Thread.Sleep(1000) solved my problem.

                IWebDriver Driver;
    
                //chromedriver.exe version2.46 path
                string path = @"C:\cd71";
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(path, "chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
                // options.AddArgument("headless");
                options.AddArgument("--window-position=-32000,-32000");
                options.AddUserProfilePreference("download.default_directory", @"c:\xmlFiles");
                options.AddUserProfilePreference("download.prompt_for_download", false);
                options.AddUserProfilePreference("disable-popup-blocking", "true");
                options.AddUserProfilePreference("safebrowsing.enabled", "true");
                Driver = new ChromeDriver(driverService, options);
    
                try
                {
                     Driver.Navigate().GoToUrl(url);
                     Thread.Sleep(1000);
                     //other works like: XML parse
                }
                catch
                {
    
                }
    

提交回复
热议问题