uploading files using selenium

Uploading files is pretty easy in selenium.Simply go to page where we want to upload the files get the xpath of the browse button.Note the browse button will have a tag name like input But its type should always be file i.e something like this

<input id="photo" type="file" name="photo"/>

Then simply add the sendkeys command to the xpath with the location of the file we want to upload.

driver.findElement(By.xpath("//input[@id='photo']")).sendKeys("file location");