{"record":{"id":"7595c420ae4400f0","repo":"teamcapybara/capybara","slug":"attach-file-does-not-support-passing-both-a-loc","errorCode":null,"errorMessage":"`#attach_file` does not support passing both a locator and a block","messagePattern":"`#attach_file` does not support passing both a locator and a block","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/node/actions.rb","lineNumber":281,"sourceCode":"      #   @param [String, Array<String>] paths     The path(s) of the file(s) that will be attached\n      #\n      #   @option options [Symbol] match\n      #     The matching strategy to use (:one, :first, :prefer_exact, :smart). Defaults to {Capybara.configure match}.\n      #   @option options [Boolean] exact\n      #     Match the exact label name/contents or accept a partial match. Defaults to {Capybara.configure exact}.\n      #   @option options [Boolean] multiple Match field which allows multiple file selection\n      #   @option options [String, Regexp] id             Match fields that match the id attribute\n      #   @option options [String] name           Match fields that match the name attribute\n      #   @option options [String, Array<String>, Regexp] class    Match fields that match the class(es) provided\n      #   @option options [true, Hash] make_visible\n      #     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).\n      # @overload attach_file(paths, &blk)\n      #   @param [String, Array<String>] paths     The path(s) of the file(s) that will be attached\n      #   @yield Block whose actions will trigger the system file chooser to be shown\n      # @return [Capybara::Node::Element]  The file field element\n      def attach_file(locator = nil, paths, make_visible: nil, **options) # rubocop:disable Style/OptionalArguments\n        if locator && block_given?\n          raise ArgumentError, '`#attach_file` does not support passing both a locator and a block'\n        end\n\n        Array(paths).each do |path|\n          raise Capybara::FileNotFound, \"cannot attach file, #{path} does not exist\" unless File.exist?(path.to_s)\n        end\n        options[:allow_self] = true if locator.nil?\n\n        if block_given?\n          begin\n            execute_script CAPTURE_FILE_ELEMENT_SCRIPT\n            yield\n            file_field = evaluate_script 'window._capybara_clicked_file_input'\n            raise ArgumentError, \"Capybara was unable to determine the file input you're attaching to\" unless file_field\n          rescue ::Capybara::NotSupportedByDriverError\n            warn 'Block mode of `#attach_file` is not supported by the current driver - ignoring.'\n          end\n        end\n        # Allow user to update the CSS style of the file input since they are so often hidden on a page","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/node/actions.rb#L263-L299","documentation":"Error \"`#attach_file` does not support passing both a locator and a block\" thrown in teamcapybara/capybara.","triggerScenarios":"Thrown at lib/capybara/node/actions.rb:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}