簡體   English   中英

如何在使用 Selenium 下載時禁用或接受 Chrome 彈出窗口

[英]How to disable or accept the Chrome pop up while downloading using Selenium

我知道這里有人問過這個問題如何禁用“這種類型的文件可能會損害您的計算機”彈出但帖子還說給定的解決方案不適用於所有 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 嗎?”時開始下載,請提供幫助。

DesiredCapabilities cap;    

ChromeOptions 選項 = 新 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM