Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Selenium Automation Testing

  • Introduction to Automation Testing
  • Introduction to Selenium
  • Advantages and Disadvantages of Selenium WebDriver
  • Locators in Selenium
  • How to launch the browsers ? 
  • Browser Navigation Commands in Selenium
  • Handling the textbox and button using selenium
  • Handling the radio button and checkbox using selenium
  • Handling the drop downs and multi-select dropdown
  • Validate the text validation and attributes values. 
  • Handling Images
  • Handling Mouse Events
  • Handling Keyboard Events
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
  • Types of wait statement in selenium
  • How to take screenshots?
  • How to upload File in Selenium?
  • How to handle scroll function using JavaScriptExecutor?
  • How to handle basic functionality using JavaScriptExecutor?
  • How to handle advanced functionality using JavaScriptExecutor?
  • How to automate CAPTCHA?
  • How to handle cookies in selenium
View Categories
  • Home
  • Tutorials
  • Selenium Automation
  • Selenium Automation Testing
  • How to upload File in Selenium?

How to upload File in Selenium?

How to upload File in Selenium?

File upload in Selenium is very straightforward when dealing with standard HTML <input type=”file”> elements.

You simply send the file path to the input element using .sendKeys(). Selenium handles the rest (no need to interact with the OS dialog).

Sample Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class FileUploadExample {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

        WebDriver driver = new ChromeDriver();

        try {

            driver.get("https://demoqa.com/upload-download");

            WebElement uploadInput = driver.findElement(By.id("uploadFile"));
             
            // Give your absolute file path here
            uploadInput.sendKeys("C:\\path\\to\\your\\file.txt"); 

            // Optionally, verify upload
            WebElement uploadedPath = driver.findElement(By.id("uploadedFilePath"));

            System.out.println("Uploaded file path: " + uploadedPath.getText());

        } finally {

            driver.quit();

        }

    }

}

Key Points

  • The file input must not be hidden. If it is, you may need to remove the ‘hidden’ attribute with JavaScript before sending keys.
  • No need to click on the “Browse” button.
  • Path must be absolute (not relative).
  • Works on all platforms (Windows: C:\\file.txt, Mac/Linux: /Users/name/file.txt).
Selenium Automation Testing
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
How to take screenshots?How to handle scroll function using JavaScriptExecutor?
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105