Selenium Webdriver | ImpactQA
Selenium Webdriver | ImpactQA

How can I upload a file using Selenium WebDriver?

Uploading file through Selenium Webdriver can be done through the following steps:

Step 1:- Set the path of chromeDriver exe file:


Step 2:- Create an object of ChromeDriver Class :

WebDriver driver = new ChromeDriver();

Here we are doing upcasting, converting subclass object into Super Type.

Step 3:- Navigate to the web page where you have to upload the file:-

driver. (“pass the URL of the page”);

Now you have to find the upload button on the web page, use any locator(XPath, id or class name, etc..) to find that button and click on it.

WebElement uploadButton = driver.findElement(Domain Premium:“uploadBTN”));;

Step 4:- Now Enter the path of the file which you have to upload on WebPage:

WebElement uploadTextField = driver.findElement(Domain Premium:“uploadTextField”));

we are passing the path of .png file to upload on web page.
Wait till the file is uploading on the page after successfully load the file click on submit button.


Once you run this script, you will be able to upload the file effectively and get a confirmation message (Your file is uploaded and unpacked).

I hope the above steps would have given you a perspective to handle file upload using Selenium WebDriver, in your Selenium projects. If you have a unique idea or perspective to work with the file uploads, then please let us know.




P.S. We are always happy to read your comments and thoughts ;)

Written by

Leading Quality Assurance & Software Testing Company. #QAconsulting #testing #automation #performance #QA #security #Agile #DevOps #API #consulting

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store