teamcapybara/capybara · error · Capybara::FileNotFound

cannot attach file, #{path} does not exist

Error message

cannot attach file, #{path} does not exist

What it means

Error "cannot attach file, #{path} does not exist" thrown in teamcapybara/capybara.

Source

Thrown at lib/capybara/node/actions.rb:285

      #   @option options [Boolean] exact
      #     Match the exact label name/contents or accept a partial match. Defaults to {Capybara.configure exact}.
      #   @option options [Boolean] multiple Match field which allows multiple file selection
      #   @option options [String, Regexp] id             Match fields that match the id attribute
      #   @option options [String] name           Match fields that match the name attribute
      #   @option options [String, Array<String>, Regexp] class    Match fields that match the class(es) provided
      #   @option options [true, Hash] make_visible
      #     A Hash of CSS styles to change before attempting to attach the file, if `true`, `{ opacity: 1, display: 'block', visibility: 'visible' }` is used (may not be supported by all drivers).
      # @overload attach_file(paths, &blk)
      #   @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

View on GitHub (pinned to 15b5fdb76e)

When it happens

Trigger: Thrown at lib/capybara/node/actions.rb:285 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/19a7cc76a2b751c4. Report an issue: GitHub.