SeleniumHQ/selenium · error · Error::UnsupportedOperationError

no such key #{key.inspect}

Error message

no such key #{key.inspect}

What it means

Keys[key] is an internal (@api private) lookup that maps a Symbol key name to its Unicode Private-Use-Area code point from the frozen KEYS table. It raises Error::UnsupportedOperationError when the Symbol has no entry. Users normally hit this indirectly through Element#send_keys, which encodes Symbol arguments via this lookup.

Source

Thrown at rb/lib/selenium/webdriver/common/keys.rb:126

        numpad_page_down: "\ue055",
        numpad_end: "\ue056",
        numpad_home: "\ue057",
        numpad_left: "\ue058",
        numpad_up: "\ue059",
        numpad_right: "\ue05A",
        numpad_down: "\ue05B",
        numpad_insert: "\ue05C",
        numpad_delete: "\ue05D"
      }.freeze

      #
      # @api private
      #

      def self.[](key)
        return KEYS[key] if KEYS[key]

        raise Error::UnsupportedOperationError, "no such key #{key.inspect}"
      end

      #
      # @api private
      #

      def self.encode(keys)
        keys.map { |key| encode_key(key) }
      end

      #
      # @api private
      #

      def self.encode_key(key)
        case key
        when Symbol
          Keys[key]

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use a recognized Symbol from Selenium::WebDriver::Keys::KEYS such as :return, :enter, :tab, :control, :command, :escape, :arrow_down.
  2. For literal characters, pass plain Strings to send_keys instead of Symbols.
  3. Inspect Selenium::WebDriver::Keys::KEYS.keys to confirm the exact Symbol name before using it.

Example fix

# before
el.send_keys(:retun)

# after
el.send_keys(:return)
Defensive patterns

Strategy: validation

Validate before calling

unless Selenium::WebDriver::Keys::KEYS.key?(sym)
  raise ArgumentError, "#{sym.inspect} is not a valid Selenium key Symbol"
end

Type guard

def valid_key?(sym)
  sym.is_a?(Symbol) && Selenium::WebDriver::Keys::KEYS.key?(sym)
end

Try / catch

begin
  el.send_keys(sym)
rescue Selenium::WebDriver::Error::UnsupportedOperationError => e
  raise unless e.message.include?('no such key')
  el.send_keys(sym.to_s) # fall back to literal string
end

Prevention

When it happens

Trigger: Calling element.send_keys(:retun) with a misspelled Symbol. Passing a Symbol that is not a defined key name such as :enter_key or :cmd. Using :ctrl instead of the defined :control, or :cmd instead of :command.

Common situations: Typos in key Symbols. Guessing a key name that does not exist in the KEYS constant (e.g. :cmd, :altgr, :win). Assuming a key alias exists when only :command/:left_meta are defined for the meta key.

Related errors


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