[英]How can I delete a downloaded file using Selenium RemoteWebDriver?
I am writing a test to check that a file can be downloaded from a particular web page and I want it to be able to run both locally and remotely (ie on a node via Selenium grid).我正在编写一个测试来检查文件是否可以从特定的网页下载,我希望它能够在本地和远程运行(即通过 Selenium 网格在节点上运行)。 Before anyone links me to the 'do you really need to download the file?'
在任何人将我链接到“您真的需要下载文件吗?”之前article, I have already managed to download and check the file, I just need a way of deleting it after the test has completed.
文章,我已经设法下载并检查了文件,我只需要一种在测试完成后删除它的方法。 Just calling
File.delete();
只需调用
File.delete();
or similar will only work locally (as far as I'm aware) so I can't use that to delete the file from the node machine.或类似的只能在本地工作(据我所知),所以我不能用它来从节点机器上删除文件。 I'm aware of the class
org.openqa.selenium.io.TemporaryFileSystem
however I can't find any instructions for how to use it.我知道类
org.openqa.selenium.io.TemporaryFileSystem
但是我找不到有关如何使用它的任何说明。
Can anyone offer a better solution than 'just run a script on the node machine to delete the file'?谁能提供比“仅在节点机器上运行脚本以删除文件”更好的解决方案? Thanks!
谢谢!
You can make the download folder shared.您可以将下载文件夹设为共享。 \\youruser\\downloads after that you can pass this path to the File.Delete();
\\youruser\\downloads 之后,您可以将此路径传递给 File.Delete(); and it will delete the desired files.
它将删除所需的文件。
This Worked for me这对我有用
try
{
if ((new File("Path")).delete()) {
System.out.println("Pass");
} else {
System.out.println("Failed");
}
} catch (Exception ex) {
ex.printStackTrace();
}
----------simply use this code for delete file in any folder-------------------
File file = new File("C:\\Users\\Updoer\\Downloads\\Inspections.pdf");
if(file.delete())
System.out.println("file deleted");
The Below Code will sequentially delete all the files from folder下面的代码将依次删除文件夹中的所有文件
File path = new File("Path of Folder");
File[] files = path.listFiles();
for (File file : files) {
System.out.println("Deleted filename :"+ file.getName());
file.delete();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.