teamcapybara/capybara · error · ArgumentError
Capybara was unable to determine the file input you're attac
Error message
Capybara was unable to determine the file input you're attaching to
What it means
Error "Capybara was unable to determine the file input you're attaching to" thrown in teamcapybara/capybara.
Source
Thrown at lib/capybara/node/actions.rb:294
# @param [String, Array<String>] paths The path(s) of the file(s) that will be attached
# @yield Block whose actions will trigger the system file chooser to be shown
# @return [Capybara::Node::Element] The file field element
def attach_file(locator = nil, paths, make_visible: nil, **options) # rubocop:disable Style/OptionalArguments
if locator && block_given?
raise ArgumentError, '`#attach_file` does not support passing both a locator and a block'
end
Array(paths).each do |path|
raise Capybara::FileNotFound, "cannot attach file, #{path} does not exist" unless File.exist?(path.to_s)
end
options[:allow_self] = true if locator.nil?
if block_given?
begin
execute_script CAPTURE_FILE_ELEMENT_SCRIPT
yield
file_field = evaluate_script 'window._capybara_clicked_file_input'
raise ArgumentError, "Capybara was unable to determine the file input you're attaching to" unless file_field
rescue ::Capybara::NotSupportedByDriverError
warn 'Block mode of `#attach_file` is not supported by the current driver - ignoring.'
end
end
# Allow user to update the CSS style of the file input since they are so often hidden on a page
if make_visible
ff = file_field || find(:file_field, locator, **options.merge(visible: :all))
while_visible(ff, make_visible) { |el| el.set(paths) }
else
(file_field || find(:file_field, locator, **options)).set(paths)
end
end
private
def find_select_or_datalist_input(from, options)
synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
find(:select, from, **options)View on GitHub (pinned to 15b5fdb76e)
When it happens
Trigger: Thrown at lib/capybara/node/actions.rb:294 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of teamcapybara/capybara@15b5fdb76e (2026-08-21).
Data as JSON: /api/errors/f11276f92f995380.
Report an issue: GitHub.