简体   繁体   English

并行上传同一文件多次

[英]uploading same file multiple times parallely

my test website html part is below: 我的测试网站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>

Now to upload file, i am using the below code: 现在要上传文件,我正在使用以下代码:

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

but it upload the same file multiple times parallely. 但会并行上传同一文件多次。 But if i do this manually, the selected file uploaded only once. 但是,如果我手动执行此操作,则所选文件仅上传一次。

WHat is the solution here??? 哪里是解决方案???

Try to use sendkeys() on the WebElement corresponding to your <input type="file"> as: 尝试在与<input type="file">相对应的WebElement上使用sendkeys()作为:

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

-OR- -要么-

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

Try this :- 尝试这个 :-

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

Put this code after your uploading file code 在上传文件代码后放置此代码

Hope it will help you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM