如何使用带有 selenium webdriver 的 Windows 文件资源管理器选择多个文件

8

本文介绍了如何使用带有 selenium webdriver 的 Windows 文件资源管理器选择多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在自动化 UI 测试,其中涉及选择要上传的文件,我能够使用此 解决方案.

I am automating a UI test where selecting file to upload is involved, I was able to automate the file selection using this solution.

WebElement filepath=driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:\TextFile.txt");

我的问题是我需要选择很多文件来上传,在我发送的路径中是否有我应该遵循的特殊格式?因为我尝试了空格分隔的路径,但它没有用.

My issue is that I need to select many files to upload, is there a special format I should follow in the path I am sending? because I tried space-separated paths and it didn't work.

推荐答案

上传多个文件可以构造字符串添加所有绝对路径 分隔的文件如下:

To upload multiple files you can construct the character string adding all the absolute path of the files seperated by as follows:

WebElement filepath = driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:/TextFile1.txt 
 C:/TextFile2.txt 
 C:/TextFile3.txt");


参考文献

您可以在以下位置找到一些相关的详细文档:


References

You can find a couple of relevant detailed documentations in:

  • 尝试使用 Python 和 Selenium 将多个文件上传到网站,但只提取了第一个文件,而没有提取其他文件,知道为什么吗?

这篇关于如何使用带有 selenium webdriver 的 Windows 文件资源管理器选择多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14