import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FileUpload {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get(“http://www.megafileupload.com/”);
        driver.findElement(By.xpath(“//input[@class=’upload_txt’]”)).sendKeys(“path of file to be uploaded”);
        driver.findElement(By.cssSelector(“input[id=’terms’]”)).click();
        driver.findElement(By.cssSelector(“input[name=’send’]”)).click();
    }
}

 

Source: http://selenium-makeiteasy.blogspot.com