如何使用selenium webdriver从资源上传文件

时间:2016-06-22 08:57:14

标签: java maven selenium

我想上传一个带有selenium webdriver的文件。该文件位于我项目的资源文件夹中,我该怎么办?

1 个答案:

答案 0 :(得分:0)

简单的方法就是找到元素并在其中键入文档的绝对路径。

HTML代码应该与此类似:

<input type="file" name="datafile">

语法:

//Find the element of upload button and send the path
WebElement element= driver.findElement(By.name("datafile"));
element.sendKeys("C:\Users\Easy\Desktop\testfile.txt");