0
How can get or locate the element for uploading image when using bootstrap upload file.在RSPEC中使用水豚定位元素
這裏是我的html上傳。
<input id="input-id" name="user[image]" type="file" class="file" data-preview-file-type="text" data-show-preview="false" data-show-upload="false" data-show-caption="true" />
這裏是在瀏覽器中呈現的HTML:
<span class="file-input file-input-new">
<div class="kv-upload-progress hide"></div>
<div class="input-group ">
<div tabindex="-1" class="form-control file-caption kv-fileinput-caption">
<span class="file-caption-ellipsis">…</span>
<div class="file-caption-name"></div>
</div>
<div class="input-group-btn">
<button type="button" title="Clear selected files" class="btn btn-default fileinput-remove fileinput-remove-button"><i class="glyphicon glyphicon-trash"></i> Remove</button>
<button type="button" title="Abort ongoing upload" class="hide btn btn-default fileinput-cancel fileinput-cancel-button"><i class="glyphicon glyphicon-ban-circle"></i> Cancel</button>
<div class="btn btn-primary btn-file"> <i class="glyphicon glyphicon-folder-open"></i> Browse … <input id="input-id" name="user[image]" type="file" class="file" data-preview-file-type="text" data-show-preview="false" data-show-upload="false" data-show-caption="true"></div>
</div>
</div>
</span>
這裏是我的水豚碼定位和傳遞圖像:
attach_file('what_here', Rails.root + 'public/sample.jpg')
我爲嘗試了不同的價值what_here以上,但不幸單一我得到錯誤:
Failure/Error: attach_file('file-caption', Rails.root + 'public/sample.jpg')
Capybara::ElementNotFound:
Unable to find file field "file-caption(tried diff. selector here)"
請幫助!
嗨@湯姆,我很新進行rspec測試。剛開始研究它昨天。請提供示例代碼,瞭解如何在您的建議中使用/做到這一點。 –
正如我所說,它取決於如何隱藏元素,例如,如果它的不透明度爲0(你正在使用jQuery),你可以做一些像'page.execute_script(「$('選擇器到文件輸入' ).css('opacity',1)「)' –
您好@Tom,謝謝。有用 :) –