0

I am trying to upload a file using selenium webd river but couldn't get this spinet code working

driver.findElement(By.id("uploadForm:j_id135")).sendKeys("path_to_file");
driver.findElement(By.name("uploadForm:j_id139")).click();

I also tried this suggestion: File Upload using Selenium WebDriver and Java too bad didn't work for me

Any ideas?much appreciated

Community
  • 1
  • 1
user1282634
  • 131
  • 1
  • 6
  • What was the error stack trace? – niharika_neo Apr 27 '12 at 08:53
  • This seems ok (if the actual path to file is ok). Show us more, i.e. the exception thrown, maybe the two html elements. – Petr Janeček Apr 28 '12 at 12:24
  • This could be a variety of problems. Bad id/name. Browser won't recognize identifiers (IE9 does this all too often). Perhaps the element you need to interact with is hidden? Provide a stack trace to the error and we'll better be able to help you out – AndyPerfect Apr 30 '12 at 05:58

1 Answers1

0

You will have give the "id" of the actual input box (where the path is provided) when you manually click to upload a file (when working manually). In the Automation scenario we need to provide the correct id of that input box by using this command:

driver.findElement(By.id("upload")).sendKeys("/path/to/the/file");

next step is off course is click the upload button.

If you are using WebDriverBackedSelenium you can use:

selenium.type("locator", "/path/to/the/file");

selenium.click("upload_button");

Manpreet Singh
  • 3,643
  • 2
  • 18
  • 14