Selenium + Chrome驱动程序+“默认下载”文件夹在本地运行脚本时不起作用

时间:2018-09-25 15:40:26

标签: selenium selenium-chromedriver

请在下面找到我的Chrome功能。

String downloadsPath = createDownloadsFolderpath(MDC.get("suiteName"));
        MDC.put("downloadsFolderpath", downloadsPath);
        System.setProperty("downloadsFolderpath", downloadsPath);
        TestContext.get().setBrowser("Chrome", "latest");
        ChromeOptions options = new ChromeOptions();
        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("safebrowsing.enabled", "true");
        chromePrefs.put("download.default_directory", MDC.get("downloadsFolderpath"));
        chromePrefs.put("download.directory_upgrade", "true");
        chromePrefs.put("plugins.plugins_disabled", new String[] { "Adobe Flash Player", "Chrome PDF Viewer" });
        chromePrefs.put("plugins.always_open_pdf_externally", true);
        chromePrefs.put("profile.default_content_setting_values.notifications", 2);
        options.setExperimentalOption("prefs", chromePrefs);
        options.addArguments("test-type");
        options.addArguments("--ignore-certifcate-errors");
        options.addArguments("--disable-extensions");
        options.addArguments("start-maximized", "disable-popup-blocking");
        options.addArguments("disable-infobars");
        options.addArguments("--disable-application-cache");

        DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
        chromeCapabilities.setCapability("name", MDC.get("testname"));
        chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
        chromeCapabilities.setCapability("download.prompt_for_download", false);
        return addProxySettings(chromeCapabilities, proxySettings);

在本地运行脚本时,默认下载位置不起作用,实际上,在Grid中运行时,它正在起作用。 请帮助

硒版本:3.14 Chrome驱动程序-2.42 Chrome版本-69.0.3497.81

0 个答案:

没有答案