本文介绍了如何使用Selenium Webdriver上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用selenium webdriver尝试了很多关于上传文件的stackoverflow的建议,但问题仍然存在。



用户点击浏览按钮,然后显示一个新的弹出窗口然后脚本会尝试上传文件。我的代码如下:

  code> 


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

这篇关于如何使用Selenium Webdriver上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:37