【问题标题】:How to handle "Download multiple files" confirmation pop up in chrome using selenium webdriver (JAVA)?如何使用 selenium webdriver (JAVA) 处理 chrome 中弹出的“下载多个文件”确认?
【发布时间】:2019-07-02 20:03:17
【问题描述】:

View image of description...

for (int i = 0; i < getOptions.size(); i++) {
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        Thread.sleep(2000);
        System.out.println("Select Options Name: " + getOptions.get(i).getText());
        Select selctValue = new Select(
                driver.findElement(By.xpath("//ul/li[1]/div[@class='input-slect-fix-w']/select")));
        selctValue.selectByIndex(i); // Size Drop down 
        Thread.sleep(5000);
        log.info("Click on download templates link.");
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("swtemplates")));
        wf.clickOnLink(By.id("swtemplates")); // Download link 
        Thread.sleep(5000);
        String getTitleOnPage = new String(driver.getTitle());
        Assert.assertFalse(getTitleOnPage.matches("(.*)404(.*)"), "Failed download templates...");

    }

步骤:

1.) 在大小下拉列表中选择选项 1 2.) 点击链接(点击从服务器下载文件后) 3.) 在大小下拉列表中选择选项 2 4.) 点击链接(打开“下载多个文件”确认弹出。)

文件无法下载。

【问题讨论】:

  • 你可以尝试用同样的方式在 chrome 中接受警报吗?
  • try { // 检查是否存在警报 Alert alert = driver.SwitchTo().Alert(); // 如果存在,则使用警报 alert.Accept(); } catch (NoAlertPresentException ex) { //如果不存在则执行的代码。 }
  • 代码能用吗?
  • 我已尝试使用 alert.accept 并设置 chrome 选项,但我无法获得解决方案。
  • 你能给出其他解决方案吗?

标签: selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

尝试https://stackoverflow.com/a/36821119/8731685 解决方案。它对我有用。 下面的 chrome 首选项行删除了多次下载对话框并下载了所有文件。

chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 2017-02-18
    • 2017-06-26
    相关资源
    最近更新 更多