How to upload file using Selenium Webdriver?

情到浓时终转凉″ 提交于 2019-12-11 18:32:54

问题


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.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



来源:https://stackoverflow.com/questions/32781036/how-to-upload-file-using-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!