我一直试图弄清楚如何使用Watir上传文件一段时间了。
以下是我必须处理的HTML
<div class="upload-csv">
<label class="ng-binding">Upload .csv</label>
<div file-upload="" id="upload-candidates-by-csv" on-file-added="add" on-success="success" on-failure="uploadfail" on-upload-start="uploadstart" config="upload.config" class="ng-isolate-scope ng-scope custom-file-upload" style="position: relative;">
<button type="button" id="upload-candidates-by-csv-trigger" class="custom-file-upload-trigger" style="position: relative; z-index: 0;">Browse</button>
<button type="button" ng-disabled="!canUpload" class="custom-file-upload-save" disabled="disabled">Upload</button>
<div id="p18htertik11n414v95q6p6314603_html5_container" class="plupload html5" style="position: absolute; background-color: transparent; width: 220px; height: 50px; overflow: hidden; z-index: -1; opacity: 0; top: 0px; left: 120px; background-position: initial initial; background-repeat: initial initial;">
<input id="p18htertik11n414v95q6p6314603_html5" style="font-size: 999px; position: absolute; width: 100%; height: 100%;" type="file" accept="text/csv">
</div>
</div>
</div>
所以我试着这样做:
element_field = browser.file_field(:id, /html5\Z/)
element_field.set(params[:path_csv])
但是我收到了这个错误:
Watir::Wait::TimeoutError: timed out after 30 seconds, waiting for {:id=>/html5_\Z/, :tag_name=>"input", :type=>"file"} to become present
我也尝试按类设定值
class="plupload html5"
但是当使用class找到元素时,set方法不起作用。
很高兴听到社区的任何意见。感谢。