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

后端 未结 8 1649
时光取名叫无心
时光取名叫无心 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:36

    I am posting below the complete code that got file download working for me: Hope it helps :-) I am using Java-Selenium

    System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
            String downloadFilepath = "D:/MyDeskDownload";
            HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("profile.default_content_settings.popups", 0);
            chromePrefs.put("download.default_directory", downloadFilepath);
            chromePrefs.put("safebrowsing.enabled", "true"); 
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", chromePrefs);
            DesiredCapabilities cap = DesiredCapabilities.chrome();
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            cap.setCapability(ChromeOptions.CAPABILITY, options);
            WebDriver driver = new ChromeDriver(cap);
    
    0 讨论(0)
  • 2020-11-27 21:46

    For context, I had a .csv with a list of .swf flash documents and their respective urls. Since the files could only be accessed after a valid login, I couldn't use a simple requests based solution.

    Just like .xml, downloading a .swf triggers a similar prompt.

    None of the answers worked for me.

    So I stripped away all the extra arguments and settings the above answers proposed and just made the chrome instance headless.

    options.add_argument("--headless")
    
    prefs = {
        "download.default_directory": "C:\LOL\Flash",
        "download.prompt_for_download": False,
        "download.directory_upgrade": True,
    }
    options.add_experimental_option("prefs",prefs)
    
    0 讨论(0)
提交回复
热议问题