简体   繁体   中英

How to upload file using Selenium Webdriver?

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");

在此处输入图片说明

If I clicked on Browse button following popup is displayed. 在此处输入图片说明

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");

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM