Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Uploading file through Selenium Webdriver

    Uploading file is a common scenario found in many website now a days. We can handle uploading file through selenium webdriver. Below is the screenshot of upload file from chrome browser :-

    Step by step execution of Code:-

    1. First we will set the path of chrome driver :-

    2. Create a instance of ChromeDriver constructor.

    Here, WebDriver is an interface, driver is a reference variable, ChromeDriver() is a constructor, new is  a keyword and new ChromeDriver () is an object.

    3. Give the navigation of the page in which we want to upload the file :-

    4. Now we will find upload button WebElement in the page.

    Here, findElement() finds a single web element and returns as a WebElement object.

    5.  Now we will enter the file path onto the file-selection input field.

    Note :- WebDriver automatically enters the file path onto the file-selection text box of the <input type=”file”> element.

    6. Finally, we will click on the upload button.

    Below is the complete code :-

    After running this script,we will be able to upload the file successfully and we get a message similar to the one shown in below screenshot :-

    This is all about uploading files through Selenium WebDriver.

    Thanks for reading this blog 🙂

    Happy testing!!


    . . .

    Comments (3)

    Add Your Comment

  • surbhi nahta
    I genuinely enjoyed this. It was extremely educational as well as helpful. I will return to examine on new posts.
    • Rajan Dimri
      We’re glad you like our blog. Thank You!
  • Naman
    Not most of the time, it works . Is there any other option apart from using sendkeys available to upload file.
  • Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again