Selenium | Uploading a file with WebElement and sendKeys

| By Webner

How to upload files on webpage with selenium webdriver tool?

While uploading a file if it becomes difficult to handle the window dialog box to upload a file on a webpage we can use sendKeys method of WebElement. With sendkeys we have to provide local file path to file upload element.

Like this is a screenshot of a webpage to upload a file:

This is the Selenium code with which we can upload the file instead of actually recording and playing Browse button click:

WebElement element= driver.findElement("file"));

Leave a Reply

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