1

Tried lot of suggestions available on stackoverflow regarding upload file using selenium webdriver, but issue still exists.

User clicks on Browse button, then a new popup window is displayed and then script will try to upload the file. My code below:

cd.findElement(By.xpath("//*[@id='import_file']")).sendKeys("E://iMedicor - Karthik/2.Demographics/Patients_Data/Patient_One.xml");

enter image description here

If I clicked on Browse button following popup is displayed. enter image description here

File is inside E drive. Tried script like below as well, but issue is still same.

cd.findElement(By.xpath("//*[@id='import_file']")).click();
cd.switchTo().activeElement()
  .sendKeys("E://iMedicor - Karthik/2.Demographics/Patients_Data/Patient_One.xml");
Phani
  • 5,319
  • 6
  • 35
  • 43
Karthik
  • 87
  • 1
  • 5
  • 12
  • [Here is another similar question. I hope this will help you.][1] [1]: http://stackoverflow.com/questions/16896685/how-to-upload-files-using-selenium-webdriver-in-java – Subhash Kumar Sep 25 '15 at 11:31
  • I have tried solutions mentioned in that one also. But it doesn't helps me. I have two file upload fields in same page.. – Karthik Sep 25 '15 at 11:39
  • Have you tried using autoIT script? It is one of the solution mentioned in abve link. AutoIT is of great help to handle Windows(only) native dialogs. – MKay Sep 25 '15 at 11:51
  • Hi, I have tried following code.. It works for me. But problem is File Upload window is not getting closed, even the file is uploaded... `cd.findElement(By.id("import_file")).click(); cd.switchTo().activeElement() .sendKeys("E:\\iMedicor-Karthik\\2.Demographics\\Patients_Data\\Patient_One.xml"); cd.findElement(By.id("btn_submit")).click();` – Karthik Sep 25 '15 at 11:56
  • The problem is fixed now... I have used below code `cd.findElement(By.id("import_file")).sendKeys("E:\\iMedicor-Karthik\\2.Demographics\\Patients_Data\\Patient_One.xml");`. Actually the filepath caused a issue for me.. I have used `E:\\iMedicor-Karthik\\2.Demographics\\Patients_Data\\Patient_One.xml` instead of `E://iMedicor-Karthik/2.Demographics/Patients_Data/Patient_One.xml` – Karthik Sep 25 '15 at 12:04
  • Please post code in your question so it can be properly formatted. – JeffC Sep 25 '15 at 14:15
  • 1
    If you found the solution to your own problem, please post it as an answer and accept it so that question gets marked as answered. – JeffC Sep 25 '15 at 14:15

1 Answers1

0

Below code solved the issue..

cd.findElement(By.id("import_file")).sendKeys("E:\\iMedicor-Karthik\\2.Demographi‌​cs\\Patients_Data\\Patient_One.xml");

Actually the filepath caused a issue for me.. I have used

E:\\iMedicor-Karthik\\2.Demographics\\Patients_Data\\Patient_One.xml

instead of E://iMedicor-Karthik/2.Demographics/Patients_Data/Patient_One.xml

Karthik
  • 87
  • 1
  • 5
  • 12