Upload files with selenium webdriver

  • 1 Replies
  • 979 Views
Upload files with selenium webdriver
« on: April 03, 2016, 18:08:33 pm »
Is it possible to upload files in the process of an automated test ?

Re: Upload files with selenium webdriver
« Reply #1 on: April 04, 2016, 15:45:57 pm »
Yes it is possible.

If the file is on a local machine (or a mapped network drive), just type the path to the file into the file upload control.
For example:

Code
driver = webdriver.Firefox()
element = driver.find_element_by_id("Upload")
element.send_keys("C:\file.txt")

For RemoteWebDriver,
In order to enable the transfer of the file from your local machine to the remote machine so it can be uploaded, you need to set a File Detector:

Code
driver.setFileDetector(new LocalFileDetector());
WebElement upload = driver.findElement(By.id("myfile"));
upload.sendKeys("/Users/sso/path/file.txt");

 

Sitemap 1 2 3 4 5 6 7 8