我知道Selify中存在某种错误,会导致一次上传多个文件时遇到麻烦(我使用的是V4.4.0).当我try 这样做时,我可以上传第一个文件,但列表中的第二个文件将与第一个和第三个文件一起上传,以及第一个和第二个文件,结果是3x1文件,2x2文件,1x3文件.
每当我需要上传多个文件时,我会访问上传位置,上传第一个文件,保存,返回,然后再次访问并上传第二个文件,依此类推.但从技术上讲,它通过一次上传调用了几次方法.
现在我已经就位,这样的战术是不能 Select 的.我读到使用\n
作为文件字符串的分隔符可能会有帮助,但它似乎对我不起作用.
如果只发送一个文件(filepaths
是仅包含一个元素的列表),则可以很好地工作.
public ApplyFilesPO uploadFile(@NotNull List<String> filepaths) {
String filepath = String.join("\n", filepaths);
uploadFilePO.uploadFile(filepath, fileInput, progressBar);
return this; // doesn't work if list contains more than 1 element
}
这是UploadFilePO#uploadFile(String, By, By)
种方法:
public void uploadFile(String filename, By input, By progressBar) {
File file = new File(Objects
.requireNonNull(getClass().getClassLoader().getResource(filename))
.getFile());
getExistingElement(input).sendKeys(file.toString());
waitForElementToDisappear(progressBar);
}
输入为2px x 0px元素,真实用户只需点击某个按钮即可打开 Select 文件窗口.
getExistingElement
:
protected final WebElement getExistingElement(By locator) {
return wait.until(ExpectedConditions.presenceOfElementLocated(locator));
}
waitForElementToDisappear
(上传文件后立即显示进度条,上传后进度条消失,所以我添加了此方法以确保上传完成:
protected final <T> void waitForElementToDisappear(T locator) {
wait.until(isBy(locator)
? ExpectedConditions.invisibilityOfElementLocated((By) locator)
: ExpectedConditions.invisibilityOf((WebElement) locator));
}