SeleniumHQ/selenium · error · ArgumentError

invalid proxy type: #{type.inspect}, expected one of #{TYPES

Error message

invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}

What it means

Proxy#type= only accepts a Symbol that is a key in the TYPES map (:direct, :manual, :pac, :auto_detect, :system). An unknown or mistyped value raises ArgumentError and lists the valid keys. This setter is invoked indirectly by the other attribute writers (http=, ssl=, etc.) which set the type automatically.

Source

Thrown at rb/lib/selenium/webdriver/common/proxy.rb:125

      def socks_username=(value)
        self.type = :manual
        @socks_username = value
      end

      def socks_password=(value)
        self.type = :manual
        @socks_password = value
      end

      def socks_version=(value)
        self.type = :manual
        @socks_version = value
      end

      def type=(type)
        unless TYPES.key? type
          raise ArgumentError,
                "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
        end

        if defined?(@type) && type != @type
          raise ArgumentError, "incompatible proxy type #{type.inspect} (already set to #{@type.inspect})"
        end

        @type = type
      end

      def as_json(*)
        json_result = {
          'proxyType' => TYPES[type].downcase,
          'httpProxy' => http,
          'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(',').map(&:strip).reject(&:empty?) : no_proxy,
          'proxyAutoconfigUrl' => pac,
          'sslProxy' => ssl,
          'autodetect' => auto_detect,

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use a Symbol from TYPES: :direct, :manual, :pac, :auto_detect, or :system.
  2. Let the attribute writers (http=, socks=, pac=) set the type automatically instead of setting it manually.
  3. If reading type from config, convert valid strings with .to_sym after validating against TYPES.keys.

Example fix

# before
proxy = Selenium::WebDriver::Proxy.new
proxy.type = 'manual'

# after
proxy = Selenium::WebDriver::Proxy.new
proxy.type = :manual
Defensive patterns

Strategy: type-guard

Validate before calling

raise ArgumentError, 'invalid proxy type' unless Selenium::WebDriver::Proxy::TYPES.key?(type)

Type guard

def valid_proxy_type?(type)
  type.is_a?(Symbol) && Selenium::WebDriver::Proxy::TYPES.key?(type)
end

Try / catch

begin
  proxy.type = type
rescue ArgumentError => e
  raise unless e.message.include?('invalid proxy type')
  proxy.type = type.to_sym
end

Prevention

When it happens

Trigger: Calling proxy.type = 'manual' with a String instead of a Symbol. Setting proxy.type = :ftp (not a valid type). Passing an invalid type through the constructor :type key.

Common situations: Passing a String ('MANUAL') instead of a Symbol (:manual). Guessing a type name like :anonymous or :ftp. Confusing the internal Symbol with the W3C string representation.

Related errors


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