SeleniumHQ/selenium · error · Error::WebDriverError
expected HTTP proxy, got #{proxy.inspect}
Error message
expected HTTP proxy, got #{proxy.inspect} What it means
Raised as Error::WebDriverError by Http::Default#new_http_client when a proxy is configured for use (use_proxy? is true) but the proxy object does not respond to #http or its #http method returns a falsy value. The adapter needs a valid proxy URL string to construct the Net::HTTP proxy connection; without it, it cannot route traffic through the proxy.
Source
Thrown at rb/lib/selenium/webdriver/remote/http/default.rb:151
def new_request_for(verb, url, headers, payload)
req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
req.basic_auth server_url.user, server_url.password if server_url.userinfo
req.body = payload if payload
req
end
def response_for(request)
http.request request
end
def new_http_client
if use_proxy?
url = proxy.http
unless proxy.respond_to?(:http) && url
raise Error::WebDriverError,
"expected HTTP proxy, got #{proxy.inspect}"
end
proxy_uri = URI.parse(url)
Net::HTTP.new(server_url.host, server_url.port,
proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
else
Net::HTTP.new server_url.host, server_url.port
end
end
def proxy
client_config.proxy
end
def use_proxy?
return false if proxy.nil?View on GitHub (pinned to aa36b38e69)
Solutions
- Ensure the proxy object responds to #http and returns a valid URL string: Selenium::WebDriver::Proxy.new(http: 'host:8080', ssl: 'host:8080').
- If using a custom proxy object, implement #http returning a non-nil URL string.
- Verify both :http and :ssl proxy entries are set when the remote endpoint uses HTTPS.
- If you don't actually need an HTTP-client-level proxy, clear it rather than leaving a partial/broken proxy config.
Example fix
# before client.proxy = Selenium::WebDriver::Proxy.new(ssl: 'proxyhost:8080') # :http is nil # after client.proxy = Selenium::WebDriver::Proxy.new(http: 'proxyhost:8080', ssl: 'proxyhost:8080')
Defensive patterns
Strategy: type-guard
Validate before calling
# Validate the proxy object before assignment: if use_proxy && !(proxy.respond_to?(:http) && proxy.http) raise ArgumentError, 'proxy must respond to #http with a non-nil URL' end
Type guard
def valid_http_proxy?(proxy) proxy.respond_to?(:http) && !proxy.http.nil? end
Try / catch
begin
client.request(verb, url)
rescue Selenium::WebDriver::Error::WebDriverError => e
raise unless e.message.include?('expected HTTP proxy')
raise 'Configure proxy with both :http and :ssl entries'
end Prevention
- Always set both :http and :ssl on Proxy objects for HTTP-client-level proxying.
- Verify the proxy object responds to #http with a non-nil URL string.
- Test proxy connectivity independently before using it with WebDriver.
When it happens
Trigger: Setting a proxy via the HTTP client that is not a valid Selenium::WebDriver::Proxy with an :http or :ssl entry. Passing a custom proxy object missing the #http method. Configuring proxy= with a Proxy whose http and ssl are both nil. Passing a string URL to proxy= (the setter may accept it but #http won't resolve).
Common situations: Configuring an HTTP transport-level proxy (distinct from browser-level proxy capabilities) incorrectly. Passing a SOCKS proxy specification when only HTTP proxy is supported. Partial proxy config (setting only :ftp or :ssl in a way that leaves :http nil). Version changes to the Proxy API.
Related errors
- too many redirects
- Cannot use both :http_client and :client_config
- unexpected response, code=#{code}, content-type=#{content_ty
- Cannot use both :client_config and :open_timeout/:read_timeo
- Pattern must be an instance of UrlPattern. Received: '${patt
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/a93e9b5760f823bf.
Report an issue: GitHub.