Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to handle FileUpload using selenium-Webdriver

//div[@id='upload_button']
driver.findElement(By.xpath("//div[@id='upload_button']")).click();
driver.findElement(By.xpath("//div[@id='upload_button']")).sendKeys("V://Images//CSV/text.csv");

  • I have a upload button in my browser
  • written a script that will click the button and send the mentioned file from given path
  • Here it is selecting the Upload button and file explorer opening
  • Not opening path, to send the csv file

>Solution :

If //input[@type='file'] is present at least one time in the HTML-DOM, the you can directly send the keys, you do not need to

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Click on upload button
  2. Select file using explorer
  3. and upload the file.

This feature was introduced in one of the Selenium 3 versions.

Effective code:

driver.findElement(By.xpath("//input[@type='file']")).sendKeys("V://Images//CSV/text.csv");

I would recommend that use explicit wait for more stability.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading