All IT Courses 50% Off

File Upload and Download using Selenium Webdriver

In this article, we will learn how to handle file uploads and downloads.

Uploading Files

To Upload files, we will use as our test application. Through this site any user can upload files without requiring them to sign up.
In Selenium Webdriver we can Upload files by simply using the method sendKeys() on the select file input field to enter the path to the file to upload.


Let’s create a test case in which we will automate the following scenarios to handle File-Upload:

  • Invoke a Google chrome browser.
  • Open URL:
  • Click on Choose file to upload a file.
  • Click on Upload button

Now, we will create a test case step by step in order to understand of how to handle file-upload in WebDriver.

All IT Courses 50% Off

Step 1: Launch Eclipse IDE.

Step 2: Go to File > New > Click on Java Project.

Enter Project Name: Demo_FileUpload


Step 3: Right click on the Project Name and click on the New > class.


Give your Class name as “Test_Fileupload” and Select the checkbox “public static void main(String[] args) and click on “Finish” button.


Step 4: Invoke the Google Chrome browser and set the system property to the path of your chromedriver.exe file.

Here is the sample code to set Chrome driver system property:

// System Property for Chrome Driver   

 System.setProperty(“”, “ D:\\Drivers\\geckodriver.exe “); 


After that we have to initialize the Chrome driver using ChromeDriver Class. Below is the sample code to initialize Chrome driver using ChromeDriver class.

// Instantiate a ChromeDriver class.      

WebDriver driver=new ChromeDriver(); 


We will get the below code to launch Google Chrome browser after combining both of the above codes.

System.setProperty(“”, “ D:\\Drivers\\geckodriver.exe “);  

WebDriver driver=new ChromeDriver();

After that we need to navigate to the desired URL.

Below is the sample code to navigate to the desired URL:

// Launch Website  


Here is the complete code for above scenario:

import org.openqa.selenium.WebDriver;  
public class Test_Fileupload {  
    public static void main(String[] args) {  
        // System Property for Chrome Driver   
 System.setProperty("", “ D:\\Drivers\\geckodriver.exe ");  
    String baseUrl = ("");  
    WebDriver driver=new ChromeDriver();  
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Check Also
Back to top button