在运行硒脚本时在新标签页中打开文件下载后,Chrome浏览器崩溃了

时间:2019-01-07 11:25:05

标签: selenium-chromedriver chrome-web-driver

当selenium脚本单击链接时,它会打开一个新选项卡,该选项卡下载excel文件,然后chrome浏览器崩溃/关闭,后续步骤失败。相同的测试脚本可以在firefox浏览器中正常运行。没有导致故障的堆栈跟踪/日志。

            final ChromeOptions chromeOptions = new ChromeOptions();
            HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("profile.default_content_settings.popups", 0);
            chromePrefs.put("download.prompt_for_download", false);
            chromePrefs.put("download.directory_upgrade", true);
            capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
            //chromePrefs.put(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, true);
            chromePrefs.put("download.default_directory", getDownloadPath());
            Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
            perfLogPrefs.put("traceCategories", "browser,devtools.timeline,devtools");
            chromeOptions.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
            chromeOptions.setExperimentalOption("prefs", chromePrefs);
            chromeOptions.addArguments("--disable-extensions");
            // chromeOptions.addArguments("--verbose");

            chromeOptions.addArguments("--enable-logging");
            //chromeOptions.addArguments("--v=1");
            //chromeOptions.addArguments("--disable-popup-blocking");
            logger.info(chromeOptions.getExperimentalOption("perfLoggingPrefs"));
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            ChromeDriverService driverService = ChromeDriverService.createDefaultService();

            // chromeOptions.addArguments("--auto-open-devtools-for-tabs");
            if (headless) {
                // chromeOptions.addArguments("--headless");

            }
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

            ChromeDriver chrome = new ChromeDriver(driverService, capabilities);

1 个答案:

答案 0 :(得分:0)

尚无解决方案,但您可以在此处关注chromedriver错误:https://bugs.chromium.org/p/chromedriver/issues/detail?id=2730