本文主要是利用watir自身写好的方法来实现文件上传。
upload.rb
require 'watir'
@ie = Watir::IE.new
@ie.goto("D:\\test.html")
sleep(10)
@ie.file_field(:type,'file').set("D:\\test.html")
sleep(3)
test.html
<H1>watir处理对话框<H1>
<table border ="2">
<tr>
<th bgcolor = "#aaaaaa">测试内容</th>
<th bgcolor = "#aaaaaa">操作</th>
</tr>
<tr>
<td>文件上传</td>
<td><input type="file" name="attach[]" /></td>
</tr>
</table>
PS: 通过watir自身的set方法来实现文件上传选择的功能。