问题
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");
回答1:
Below code solved the issue..
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
来源:https://stackoverflow.com/questions/32781036/how-to-upload-file-using-selenium-webdriver