SeleniumHQ/selenium · error · ArgumentError
Invalid arguments: #{opts.keys}
Error message
Invalid arguments: #{opts.keys} What it means
Raised by Selenium::WebDriver::Credential#initialize when the keyword arguments contain keys other than the recognized ones (:id, :resident_credential, :rp_id, :private_key, and the optional :user_handle, :sign_count consumed via **opts). After deleting known keys from opts, if any remain, ArgumentError is raised listing the unexpected keys.
Source
Thrown at rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb:67
rp_id: opts['rpId'],
private_key: decode(opts['privateKey']),
sign_count: opts['signCount'],
user_handle: user_handle)
end
end
attr_reader :id, :resident_credential, :rp_id, :user_handle, :private_key, :sign_count
alias resident_credential? resident_credential
def initialize(id:, resident_credential:, rp_id:, private_key:, **opts)
@id = id
@resident_credential = resident_credential
@rp_id = rp_id
@user_handle = opts.delete(:user_handle) { nil }
@private_key = private_key
@sign_count = opts.delete(:sign_count) { 0 }
raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
end
#
# @api private
#
def as_json(*)
credential_data = {'credentialId' => Credential.encode(id),
'isResidentCredential' => resident_credential?,
'rpId' => rp_id,
'privateKey' => Credential.encode(private_key),
'signCount' => sign_count}
credential_data['userHandle'] = Credential.encode(user_handle) if user_handle
credential_data
end
end # Credential
end # WebDriver
end # SeleniumView on GitHub (pinned to aa36b38e69)
Solutions
- Use only recognized snake_case keys: id:, resident_credential:, rp_id:, private_key:, user_handle:, sign_count:.
- Prefer the factory methods Credential.resident(...) and Credential.non_resident(...) which guide correct usage.
- If constructing from external data, filter keys before passing: credential_data.slice(:id, :resident_credential, :rp_id, :private_key, :user_handle, :sign_count).
Example fix
// before cred = Selenium::WebDriver::Credential.new( id: [1, 2, 3], resident_credential: true, rpId: 'example.com', # camelCase typo privateKey: [4, 5, 6], # camelCase typo signCount: 0 # camelCase typo ) // after cred = Selenium::WebDriver::Credential.new( id: [1, 2, 3], resident_credential: true, rp_id: 'example.com', private_key: [4, 5, 6], sign_count: 0 ) # or use factory: cred = Selenium::WebDriver::Credential.resident( id: [1, 2, 3], rp_id: 'example.com', private_key: [4, 5, 6] )
Defensive patterns
Strategy: validation
Validate before calling
VALID_CREDENTIAL_KEYS = %i[id resident_credential rp_id private_key user_handle sign_count].freeze
def safe_credential(opts)
unknown = opts.keys - VALID_CREDENTIAL_KEYS
raise ArgumentError, "Unknown Credential keys: #{unknown}. Valid: #{VALID_CREDENTIAL_KEYS}" unless unknown.empty?
Selenium::WebDriver::Credential.new(**opts)
end Type guard
def valid_credential_opts?(opts) (opts.keys - %i[id resident_credential rp_id private_key user_handle sign_count]).empty? end
Try / catch
begin
cred = Selenium::WebDriver::Credential.new(**opts)
rescue ArgumentError => e
raise unless e.message.include?('Invalid arguments')
# filter to known keys and retry
filtered = opts.slice(:id, :resident_credential, :rp_id, :private_key, :user_handle, :sign_count)
cred = Selenium::WebDriver::Credential.new(**filtered)
end Prevention
- Use snake_case Ruby kwargs, not camelCase JSON field names from the WebAuthn spec.
- Prefer the Credential.resident and Credential.non_resident factory methods for guided construction.
- When building credentials from external/JSON data, map camelCase to snake_case explicitly.
When it happens
Trigger: Calling Credential.new(id: ..., rp_id: ..., foo: 'bar') with a typo'd key like :rpId (camelCase) instead of :rp_id. Passing :signCount instead of :sign_count. Passing an extra key that doesn't belong (e.g., :name, :description).
Common situations: Copying JSON field names (camelCase) from the WebAuthn spec or DevTools protocol directly as Ruby keyword args (which use snake_case). Typos in keyword argument names. Passing a Hash constructed from external data with unexpected keys.
Related errors
- Invalid arguments: #{opts.keys}
- incompatible proxy type #{type.inspect} (already set to #{@t
- cannot find element by #{how.inspect}
- cannot find elements by #{how.inspect}
- expected #{arg.inspect}:#{arg.class} to respond to #shift
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/76e9e1e400b9d926.
Report an issue: GitHub.