0

I am trying to upload a file using "sendKeys" on iframe but its always opening Browse window instead of uploading file. following is my code

driver.switchTo().frame(3);
WebElement UploadElement=driver.findElement(By.cssSelector(".btn"));
UploadElement.sendKeys("D:\\Report.pdf");

Thanks.

1

2 Answers 2

2

After doing much R&D i found the solution of this. I used AutoIT tool to upload file from the system if Browse button is placeed on the iFrame.

1

Directly send the file path to the id, like so

driver.findElement(By.id("button id")).sendKeys("D:\\Report.pdf");
driver.findElement(By.xpath("your xpath")).sendKeys("D:\\Report.pdf");

The above step is the answer for your first two steps

Click on Browse Select a file to upload For the third step(click upload), looking at the screen capture I do not see any button which says "Upload". So just click "Save" and I assume that your file will successfully get uploaded

3
  • i have updated my script like below but its still not working. is there can be issue with iframe ? driver.switchTo().frame(3); driver.findElement(By.xpath("//html[@id='ng-app']/body/div/div[2]/div[2]/div/section/div/div/button")).sendKeys("D:\\Report.pdf");
    – sunil
    Jan 4, 2019 at 11:39
  • what error you getting staleElement or something else
    – Rao
    Jan 4, 2019 at 13:48
  • i am gettinng error like "Chrome is not reachable."
    – sunil
    Jan 7, 2019 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.