How to upload files when testing using Selenium Webdriver

You can use the following code to set a file path to the file upload control.

WebElement file = driver.findElement(By.id("control_id"));
file.sendKeys("/full/path/to/file");

You need to pass full path to the sendKeys() for it to work. Otherwise sendKeys() fails silently.

comments powered by Disqus