环境:
windows xp,
firefox 11.0,
selenium 2.0
假设我们有一个如下所示的上传按钮
<input id="upload", type=“file”>
可以使用如下代码实现上传
Element btn = driver.findElement(By.id('upload'));
btn.click();
btn.sendKeys([your_img_path])
// click 上传或者确认按钮
注意,这样做,不会出现native dialog, 但是最终效果和手动操作是一致的
参考:http://blog.sina.com.cn/s/blog_7407815a010170yf.html