SeleniumHQ/selenium · error · TypeError

expected one of # , got # :#

Error message

expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}

What it means

Raised by Firefox::Profile#[]= (TypeError) when the preference value is not one of VALID_PREFERENCE_TYPES ([TrueClass, FalseClass, Integer, Float, String]). Firefox about:config preferences only accept boolean, numeric, or string scalar values, so the setter rejects anything else (arrays, hashes, symbols, nil).

Solutions

  1. Convert the value to one of the allowed types before assigning (symbol->string via to_s, etc.).
  2. Use true/false for booleans, integers/floats for numbers, and plain strings for text.
  3. If you need to remove a preference, manage the underlying prefs hash directly rather than assigning nil.

Example fix

// before
profile['network.proxy.type'] = :auto  # Symbol -> TypeError

// after
profile['network.proxy.type'] = 'auto'  # plain string
# or for known numeric codes
profile['network.proxy.type'] = 4
Defensive patterns

Strategy: type-guard

Validate before calling

ALLOWED = [TrueClass, FalseClass, Integer, Float, String]
value = coerce(value) unless ALLOWED.any? { |t| value.is_a?(t) }
profile[key] = value

Type guard

def valid_pref_value?(value)
  [TrueClass, FalseClass, Integer, Float, String].any? { |t| value.is_a?(t) }
end

Prevention

When it happens

Trigger: Calling profile[key] = value with a Symbol (e.g. :none), an Array, a Hash, nil, or any non-scalar; passing a numeric as a string when a real number was intended is fine, but a Symbol like :auto will fail.

Common situations: Copying preference values from documentation that use symbols; deserializing JSON config into nested structures and assigning a Hash; passing nil to 'unset' a preference (not supported).

Related errors


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

Appendix: source

Thrown at rb/lib/selenium/webdriver/firefox/profile.rb:101

          install_extensions(profile_dir)
          delete_lock_files(profile_dir)
          delete_extensions_cache(profile_dir)
          update_user_prefs_in(profile_dir)

          profile_dir
        end

        #
        # Set a preference for this particular profile.
        #
        # @see http://kb.mozillazine.org/About:config_entries
        # @see http://preferential.mozdev.org/preferences.html
        #

        def []=(key, value)
          unless VALID_PREFERENCE_TYPES.any? { |e| value.is_a? e }
            raise TypeError, "expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}"
          end

          if value.is_a?(String) && Util.stringified?(value)
            raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}"
          end

          @additional_prefs[key.to_s] = value
        end

        def port=(port)
          WebDriver.logger.deprecate('Firefox::Profile#port=', 'the Service class', id: :firefox_profile)
          self[WEBDRIVER_PREFS[:port]] = port
        end

        def secure_ssl=(value)
          WebDriver.logger.deprecate('Firefox::Profile#secure_ssl=', id: :firefox_profile)
          @secure_ssl = value
        end

View on GitHub (pinned to aa36b38e69)