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



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

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

如果您正在使用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的值设置为所需的位置。

最新更新