環境:
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