Upload File Using SendKeys In Selenium WebDriver



Upload File Using SendKeys In Selenium WebDriver

In this blog, we are going to learn, how we can upload file by using the SendKeys method in Selenium Web Driver.



To upload a file we need to provide an absolute path of document into the text box where we need to upload the file.


To show the example, I have created one simple HTML page with one input box and the Submit button.



Below is the HTML for the above File upload Page


Below Code Snippet will upload a file using SendKeys()

Result of above code execution would be




SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
December 19, 2018 at 10:55 AM

This will work if the file is in local machine, if you are using Grid or Sauce lab kinda the you have use File Detector, Built in method to upload files.
LocalFileDetector detector = new LocalFileDetector();
((RemoteWebElement)ele).setFileDetector(detector);
ele.sendKeys(detector.getLocalFile("./Resume.pdf")
.getAbsolutePath());

Reply
avatar
December 19, 2018 at 10:56 AM

This will work if the file is in local machine, if you are using Grid or Sauce lab kinda the you have use File Detector, Built in method to upload files.
LocalFileDetector detector = new LocalFileDetector();
((RemoteWebElement)ele).setFileDetector(detector);
ele.sendKeys(detector.getLocalFile("./Resume.pdf")
.getAbsolutePath());

Reply
avatar