noor
noor

Reputation: 3004

uploading same file multiple times parallely

my test website html part is below:

<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???

Upvotes: 0

Views: 867

Answers (2)

Mukesh Takhtani
Mukesh Takhtani

Reputation: 862

Try to use sendkeys() on the WebElement corresponding to your <input type="file"> as:

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);

Upvotes: 1

Shubham Jain
Shubham Jain

Reputation: 17593

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

Upvotes: 0

Related Questions