Capybara::ElementNotFound: Unable to find file field “file”

佐手、 提交于 2019-12-05 04:01:13

Capybara 2x (capybara issue) doesn't find hidden elements by default.

You can either set ignore_hidden_elements to false:

Capybara.ignore_hidden_elements = false

Or simply add :visible option to your method:

within '.upload_csv' do
  attach_file('file', "#{Rails.root}/spec/acceptance/test_uploads/input_output.csv", visible: false)
    click_button 'Upload'
end

This solved my problem.

Note: :visible option is also supported by most of Capybara methods that internally work with Capybara::Query (like find, all, has_css?, have_selector etc.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!