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();
代码设置了下载路径,但实际上没效果,还是原来谷歌浏览器设置的下载地址