梵印  bingo 2022-04-08 14:43 采纳率: 78.3%
浏览 23
已结题

java+Selenium设置下载路径,但没效果


System.setProperty("webdriver.chrome.driver","D:\\myProject\\jSoup\\chromedriver.exe");
        ChromeOptions chromeOptions = new ChromeOptions();
        String downLoad="C:\\Users\\trs\\Desktop\\输出EXCEL\\";
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("download.default_directory",downLoad);
        hashMap.put("profile.default_content_settings.popups",0);
        hashMap.put("profile.content_settings.exceptions.automatic_downloads.*.setting",1);
        hashMap.put("download.prompt_for_download",false);
        chromeOptions.setExperimentalOption("prefs", hashMap);
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptions);
        String url="https://ourworldindata.org/grapher/share-people-vaccinated-covid?tab=table&time=latest";
        ChromeDriver driver = new ChromeDriver(capabilities);
        driver.get(url);
        Thread.sleep(5000);
        driver.executeScript("window.scrollTo(0,300)");
        WebElement tabs = driver.findElement(By.className("tabs"));
        WebElement element = tabs.findElement(By.className("download-tab-button"));
        WebElement a = element.findElement(By.tagName("a"));
        //driver.executeScript("arguments[0].click();",element);
        a.click();
        Thread.sleep(5000);
        List<WebElement> elements = driver.findElements(By.className("grouped-menu-list"));
        WebElement webElement = elements.get(1);
        webElement.click();
        Thread.sleep(10000);
        driver.quit();

代码设置了下载路径,但实际上没效果,还是原来谷歌浏览器设置的下载地址

  • 写回答

2条回答 默认 最新

  • 梵印  bingo 2022-05-11 17:31
    关注

    是selenium依赖过低的问题,升级之后就正常了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月19日
  • 已采纳回答 5月11日
  • 创建了问题 4月8日

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题