Hi Jigyasa, following piece of code will give you an idea how you can upload a file to server using Selenium Webdriver:
public class UploadFile{
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Users\\Anvi_R\\Downloads\\ExtractedFiles\\geckodriver-v0.24.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("http://www.tinyupload.com/");
// search the browse button
WebElement uploadElement = driver.findElement(By.className("pole_plik"));
// click the browse button and enter the file path
uploadElement.sendKeys("C:\\Users\\Anvi_R\\Desktop\\Q1.png");
// click the "UploadFile" button
driver.findElement(By.xpath("/html/body/table/tbody/tr[4]/td/table/tbody/tr/td[2]/form/table/tbody/tr[2]/td[1]/img")).click();
}
}