实际上,也有一种内置的技术。它应该可以在所有浏览器和操作系统中使用。
Selenium 2(WebDriver)Java示例:
// assuming driver is a healthy WebDriver instanceWebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));fileInput.sendKeys("C:/path/to/file.jpg");这个想法是将文件的绝对路径直接发送到一个元素,您通常会单击该元素以获取模式窗口-即
<input type='file' />element。



