使用Selenium下载时如何禁用或接受Chrome弹出窗口 [英] How to disable or accept the Chrome pop up while downloading using Selenium

查看:159
本文介绍了使用Selenium下载时如何禁用或接受Chrome弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在这里但是帖子还说,给定的解决方案不适用于所有chrome版本.

I know this question was asked here How to disable 'This type of file can harm your computer' pop up But the post also says the given solution does not work for all the chrome version.

我尝试了所有可能的事情仍然无法禁用弹出窗口或选择保持文件按钮.我使用的是chrome版本62.0.3202.89(正式版本)(32位)

I tried every possible thing still can not disable the pop up or select keep the file button.I am using chrome Version 62.0.3202.89 (Official Build) (32-bit)

我使用了以下代码,但无法正常工作...:(

I used below code but not working...:(

    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadDir);
    options.setExperimentalOption("prefs", chromePrefs);
    chromePrefs.put("safebrowsing.enabled", "true");
    options.addArguments("--safebrowsing-disable-download-protection");
    //options.addArguments("--test-type");
   // options.addArguments("--disable-extensions"); //to disable browser extension popup
    //options.addArguments("--safebrowsing-disable-extension-blacklist");

如果有人在弹出chrome警告时说这种类型的文件可能会损害您的计算机.您是否仍要保留该jar?",请帮助,如果有人知道如何开始下载.

Please help if anyone knows how to make the download start when chrome warning pops up saying "This type of file can harm your computer.Do you want to keep the jar anyway?"

推荐答案

DesiredCapabilities cap;    

ChromeOptions选项=新的ChromeOptions();

ChromeOptions options = new ChromeOptions();

    String downloadFilepath = "K:\\";
    HashMap<String, Object> setPath = new HashMap<String, Object>();    
    setPath.put("download.default_directory", downloadFilepath); //to set path 
    setPath.put("safebrowsing.enabled", "false"); // to disable security check eg. Keep or cancel button

    HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
    options.setExperimentalOption("prefs", setPath);
    options.addArguments("--disable-extensions"); //to disable browser extension popup


    cap = DesiredCapabilities.chrome();
    cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
    cap.setCapability(ChromeOptions.CAPABILITY, options);

这篇关于使用Selenium下载时如何禁用或接受Chrome弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆