SeleniumHQ/selenium · error · TypeError
#{source.type} is not a valid input type
Error message
#{source.type} is not a valid input type What it means
Raised as TypeError by TypingInteraction#assert_source when the source passed to TypingInteraction.new(source, type, key) is not a KeyInput. TypingInteraction encodes keyDown/keyUp and is only valid on a key input source. Reached via KeyInput#create_key_down / create_key_up (which pass self) or by direct construction.
Source
Thrown at rb/lib/selenium/webdriver/common/interactions/typing_interaction.rb:39
module WebDriver
module Interactions
#
# Actions related to pressing keys.
#
# @api private
#
class TypingInteraction < Interaction
attr_reader :type
def initialize(source, type, key)
super(source)
@type = assert_type(type)
@key = Keys.encode_key(key)
end
def assert_source(source)
raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? KeyInput
end
def assert_type(type)
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
KeyInput::SUBTYPES[type]
end
def encode
{type: @type, value: @key}
end
end # TypingInteraction
end # Interactions
end # WebDriver
end # Selenium
View on GitHub (pinned to aa36b38e69)
Solutions
- Use the public key DSL (driver.action.key_down('a').key_up('a').perform) which obtains a KeyInput internally.
- If constructing TypingInteraction directly, ensure source.is_a?(Selenium::WebDriver::Interactions::KeyInput).
Example fix
# before
type_action = Selenium::WebDriver::Interactions::TypingInteraction.new(pointer, :down, 'a') # => TypeError
# after
key = Selenium::WebDriver::Interactions::KeyInput.new
key.create_key_down('a') Defensive patterns
Strategy: type-guard
Type guard
def key_input?(src) src.is_a?(Selenium::WebDriver::Interactions::KeyInput) end TypingInteraction.new(src, type, key) if key_input?(src)
Prevention
- Use driver.action.key_down/key_up rather than constructing TypingInteraction directly.
- Keep key actions wired only to KeyInput instances.
When it happens
Trigger: Constructing Interactions::TypingInteraction.new(pointer, :down, 'a') or with a WheelInput/NoneInput source. Reached through the public key_down/key_up DSL only if the key input lookup is bypassed.
Common situations: Custom action-builder code that wires a key press onto a pointer or wheel device; refactors that swap device variables.
Related errors
- #{type.inspect} is not a valid key subtype
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/9bd04121b8b1e3dd.
Report an issue: GitHub.