How to upload files using Selenium WebDriver

In this post we learn How to upload files using Selenium WebDriver.Selenium support only browser level automation testing ,does not have any API to read and write external data like Excel, Database.


What is CSV files.?


CSV stands for comma separated values, in our applications we have to take data from existing csv files.Download CSV jar from this MavenRepository

Add jar file to our project same as Configure build path in Eclipse project.

How to add jar ->Right click on project > Select Build path > Select configure build path> Add external jar> Select the jar which was downloaded.

Please follow below code to upload the csv file.

Create Webelement for Upload button
WebElement upload=driver.findElement(By.id("UploadFile"));
Use send keys option to upload saved csv file as below
upload.sendKeys("E:/CSV_FILE/header_sample.csv");
Automatically it will take above given path and csv file and click on submit button to upload the file as below
driver.findElement(By.id("savebtn")).click();
Wait for the file uploading time
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

Conclusion:

In above post you learned how to upload a files using selenium web driver,if you have any concern regarding above post please add comments to my post and always suggestions are appreciated here.

Post a Comment

1 Comments

  1. My brother recommended I might like this blog. He was totally right.
    This post actually made my day. You can not imagine simply how much time I had spent for this info!

    Thanks!

    ReplyDelete