我在标签内隐藏了输入:
<label for="upload">
<input class="hidden" type="file" name="file[picture]">
</label>
当我单击标签时,我将附加一个文件,然后确认。
弹出该模式窗口后,我需要找到适当的div类。
如何在水豚的帮助下进行测试?
更新: Capybara 2.12添加了一个make_visible
选项,attach_file
因此如果使用2.12+,则可以先尝试
attach_file('file[picture]', 'path/to/file.png', make_visible: true)
在直接使用execute_script
自己之前
文件输入是一种特殊情况,因为它们经常出于样式原因而被隐藏,并使用系统模式进行交互。Capybara使得很难填充页面上的隐藏字段,因为用户通常无法与它们进行交互,因此对于文件输入,通常的做法是execute_script
使它们可见并进行填充。
execute_script("$('input[name=\"file[picture]\"]').removeClass('hidden')") # assumes you have jQuery available - if not change to valid JS for your environment
attach_file('file[picture]', 'path/to/file.png') # takes id, name or label text of field not a random selector
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句