如何使用Selenium Webdriver上传文件? [英] How to upload file using Selenium Webdriver?
问题描述
用户点击浏览按钮,然后显示一个新的弹出窗口然后脚本会尝试上传文件。我的代码如下:
cd.findElement(By.xpath(// * [@ id ='import_file']) ).sendKeys(E:// iMedicor - Karthik / 2.Demographics / Patients_Data / Patient_One.xml);
如果我点击浏览按钮弹出显示。
文件在E盘里面。尝试了下面的脚本,但问题仍然是一样的。
cd.findElement(By.xpath(// * @ ID = 'import_file']))点击();
cd.switchTo()。activeElement()
.sendKeys(E:// iMedicor - Karthik / 2.Demographics / Patients_Data / Patient_One.xml);
下面的代码解决了这个问题..
$ b
cd.findElement(By.id(import_file))。sendKeys(E:\\iMedicor-Karthik\\2.Demographi cs \\Patients_Data\\Patient_One.xml);
实际上文件路径对我造成了一个问题..我已使用
E:\\iMedicor-Karthik\\2.Demographics\\Patients_Data\\Patient_One。 xml
而不是 E://iMedicor-Karthik/2.Demographics/Patients_Data/Patient_One.xml 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.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
这篇关于如何使用Selenium Webdriver上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!