我能够在 Chrome 中更改下载位置,但是当我为 Edge 浏览器执行此操作时,EdgeOptions 不存在 setExperimentalOptions 方法。我正在使用 Selenium 3.141.59 Java。
String location = System.getProperty("user.dir") + "\\Downloads";
HashMap preferences = new HashMap();
preferences.put("download.default_directory", location);
EdgeOptions options = new EdgeOptions();
options.setExperimentalOption("prefs", preferences); //setExperimentalOption is not existed for Edge
System.setProperty("webdriver.edge.driver","C:\\Users\\User\\Desktop\\Selenium\\Browsers\\Edge\\msedgedriver.exe");
WebDriver driver = new EdgeDriver(options);
driver.manage().window().maximize();
driver.get("https://file-examples.com/index.php/sample-documents-download/sample-doc-download/");
driver.findElement(By.xpath("//tbody/tr[1]/td[5]/a[1]")).click();