无法使用 selenium 将文件从 C:downloads 移动到其他位置

时间:2021-06-03 05:41:44

标签: java eclipse selenium automation

我正在使用 selenium 下载一个文件,现在它已保存在路径 C:Downloads 中,但我希望将其保存在我喜欢保存的单独路径中。

使用 selenium,我可以将该桌面文件从一个位置移动到另一个我想要的位置,或者我可以在 Eclipse 本身中设置一个路径,以便在执行脚本时下载文件。

1 个答案:

答案 0 :(得分:0)

如果您使用的是 Java 7 或更新版本,那么您可以使用 Files.move(from, to, CopyOption... options)

Files.move(Paths.get("C:\\Downloads\\Kumar.txt"), Paths.get("Full new file path location"));

或者使用 Selenium (Options) :

protected static WebDriver driver;

@Test
public void testSO() throws InterruptedException {
  ChromeOptions options =  new ChromeOptions();
  options.addArguments("download.default_directory = C:/Downloads");
  driver = new ChromeDriver(options);
}

您可以将 download.default_directory 的值设置为您想要的位置。

相关问题