{"record":{"id":"70baaca72835c07f","repo":"SeleniumHQ/selenium","slug":"device-inspect-is-not-a-valid-inputdevice","errorCode":null,"errorMessage":"#{device.inspect} is not a valid InputDevice","messagePattern":"#(.+?) is not a valid InputDevice","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/action_builder.rb","lineNumber":240,"sourceCode":"      # Adds pauses for all devices but the given devices\n      #\n      # @param [Array[InputDevice]] action_devices Array of Input Devices performing an action in this tick.\n      #\n\n      def tick(*action_devices)\n        return if @async\n\n        @devices.each { |device| device.create_pause unless action_devices.include? device }\n      end\n\n      #\n      # Adds an InputDevice\n      #\n\n      def add_input(device)\n        device = Interactions.send(device) if device.is_a?(Symbol) && Interactions.respond_to?(device)\n\n        raise TypeError, \"#{device.inspect} is not a valid InputDevice\" unless device.is_a?(Interactions::InputDevice)\n\n        unless @async\n          max_device = @devices.max { |a, b| a.actions.length <=> b.actions.length }\n          pauses(device: device, number: max_device.actions.length) if max_device\n        end\n        @devices << device\n        device\n      end\n    end # ActionBuilder\n  end # WebDriver\nend # Selenium\n","sourceCodeStart":222,"sourceCodeEnd":252,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/action_builder.rb#L222-L252","documentation":"ActionBuilder#add_input validates that the device is an instance of Interactions::InputDevice. If you pass it a Symbol it first tries to resolve it via Interactions.send(symbol); anything that is still not an InputDevice afterward raises TypeError. This guards the type of devices added to an action sequence.","triggerScenarios":"Calling action_builder.add_input(obj) where obj is not an InputDevice and not a resolvable Symbol (e.g. a String, a Hash, nil, or an unrelated object).","commonSituations":"Passing a string name instead of a symbol, passing a device instance from the wrong library, building a custom device without subclassing Interactions::InputDevice, nil from a failed lookup.","solutions":["Pass a known symbol resolvable by Interactions (e.g. :keyboard, :mouse, :wheel, :pen) or an InputDevice instance.","For custom devices, subclass Selenium::WebDriver::Interactions::InputDevice.","If passing a name, use a Symbol not a String.","Construct devices via Interactions APIs (e.g. Interactions.pointer(...)) rather than ad-hoc objects."],"exampleFix":"// before\naction_builder.add_input('mouse')\n// after\naction_builder.add_input(:mouse)","handlingStrategy":"type-guard","validationCode":"def input_device?(device)\n  device.is_a?(Selenium::WebDriver::Interactions::InputDevice)\nend","typeGuard":"def input_device?(device)\n  device.is_a?(Selenium::WebDriver::Interactions::InputDevice)\nend","tryCatchPattern":"begin\n  action_builder.add_input(device)\nrescue TypeError => e\n  raise unless e.message =~ /not a valid InputDevice/\n  action_builder.add_input(device.to_sym)\nend","preventionTips":["Pass Symbols (:keyboard, :mouse, :wheel, :pen) or InputDevice instances only.","Subclass Interactions::InputDevice for custom devices.","Build devices via the Interactions factory methods rather than ad-hoc objects."],"tags":["actions","input-device","typeerror","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}