并行多次上传同一个文件

uploading same file multiple times parallely

我的测试网站html部分如下:

<button id="btnUpload" type="button" class="btn fileinput-button fileinputs">
    <span class="icon wc-upload"></span>
    <span>Upload</span>
    <input type="file" name="file" multiple=""></button>

现在上传文件,我使用下面的代码:

driver.findElement(By.cssSelector("#btnUpload")).sendKeys(AppConstant.RESOURCE_DIR+fileName);

但它会并行多次上传同一个文件。但如果我手动执行此操作,则所选文件仅上传一次。

这里的解决方法是什么???

试试这个:-

driver.findElement(By.cssSelector("#btnUpload")).sendKeys(Keys.chord(Keys.CLEAR));

将此代码放在上传文件代码之后

希望对您有所帮助

尝试在 WebElement 上使用 sendkeys() 对应于您的 <input type="file"> 作为:

driver.findElement(By.xpath("//input[@type='file']")).sendKeys(AppConstant.RESOURCE_DIR+fileName);

-或-

WebElement inputFileControl = driver.findElement(By.xpath("//input[@type='file']"))
inputFileControl.sendKeys(AppConstant.RESOURCE_DIR+fileName);