【问题标题】:How to disable or accept the Chrome pop up while downloading using Selenium如何在使用 Selenium 下载时禁用或接受 Chrome 弹出窗口
【发布时间】:2018-06-21 12:12:19
【问题描述】:

我知道有人在这里问过这个问题How to disable 'This type of file can harm your computer' pop up 但是帖子还说给定的解决方案不适用于所有 chrome 版本。

我尝试了所有可能的方法仍然无法禁用弹出窗口或选择保留文件按钮。我使用的是 chrome 版本 62.0.3202.89 (Official Build) (32-bit)

我使用了下面的代码但没有工作...:(

    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 吗?”时开始下载,请提供帮助。

【问题讨论】:

标签: java google-chrome selenium


【解决方案1】:
DesiredCapabilities cap;    

ChromeOptions 选项 = 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);

【讨论】:

  • setPath.put("safebrowsing.enabled", "false");你必须把它弄假
  • 感谢您的帮助,但仅代码答案尚未完成。请解释做了什么以及为什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-20
  • 1970-01-01
  • 1970-01-01
  • 2019-02-23
  • 2016-11-16
  • 1970-01-01
  • 2021-07-20
相关资源
最近更新 更多