SeleniumHQ/selenium · error · ArgumentError

detector must respond to #call

Error message

detector must respond to #call

What it means

UploadsFiles#file_detector= validates that the detector is nil or an object responding to #call (i.e. a callable / proc / lambda). A non-callable value raises ArgumentError because the detector is later invoked with send_keys arguments to map them to file paths.

Source

Thrown at rb/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb:53

        #
        # Example:
        #
        #     driver = Selenium::WebDriver.for :remote
        #     driver.file_detector = lambda do |args|
        #        # args => ["/path/to/file"]
        #        str = args.first.to_s
        #        str if File.exist?(str)
        #     end
        #
        #     driver.find_element(:id => "upload").send_keys "/path/to/file"
        #
        # By default, no file detection is performed.
        #
        # @api public
        #

        def file_detector=(detector)
          raise ArgumentError, 'detector must respond to #call' unless detector.nil? || detector.respond_to?(:call)

          bridge.file_detector = detector
        end
      end # UploadsFiles
    end # DriverExtensions
  end # WebDriver
end # Selenium

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Assign a callable: driver.file_detector = ->(args) { ... } that returns a file path String or nil.
  2. Pass nil to disable file detection.
  3. Ensure any custom detector object implements #call (e.g. define def call(args) ... end).
  4. Use a lambda/proc, not a method name or class.

Example fix

// before
driver.file_detector = 'local'
driver.file_detector = MyUploader
// after
driver.file_detector = ->(args) { args.first.to_s if File.exist?(args.first.to_s) }
Defensive patterns

Strategy: type-guard

Validate before calling

def callable_detector?(d)
  d.nil? || d.respond_to?(:call)
end

raise ArgumentError, 'detector must be callable' unless callable_detector?(detector)
driver.file_detector = detector

Type guard

def callable?(obj)
  obj.respond_to?(:call)
end

Try / catch

begin
  driver.file_detector = detector
rescue ArgumentError => e
  raise unless e.message =~ /must respond to #call/
  driver.file_detector = nil
end

Prevention

When it happens

Trigger: Calling driver.file_detector = value where value is neither nil nor a callable — e.g. a String, a Class, an instance without a #call method, or an Array.

Common situations: Assigning a class name or method name instead of a proc, passing a custom object that forgets to define #call, intending 'auto-detect' but passing a non-callable sentinel.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/e071bc7776a538bf. Report an issue: GitHub.