SeleniumHQ/selenium · error · ArgumentError
Cookie name cannot be null or empty
Error message
Cookie name cannot be null or empty
What it means
Manager#delete_cookie requires a non-nil, non-blank cookie name. It explicitly rejects nil, empty strings, and whitespace-only names by calling name.to_s.strip.empty?. This guards against sending an invalid delete request to the driver endpoint.
Source
Thrown at rb/lib/selenium/webdriver/common/manager.rb:82
#
# Get the cookie with the given name
#
# @param [String] name the name of the cookie
# @return [Hash] the cookie, or throws a NoSuchCookieError if it wasn't found.
#
def cookie_named(name)
convert_cookie(@bridge.cookie(name))
end
#
# Delete the cookie with the given name
#
# @param [String] name the name of the cookie to delete
#
def delete_cookie(name)
raise ArgumentError, 'Cookie name cannot be null or empty' if name.nil? || name.to_s.strip.empty?
@bridge.delete_cookie name
end
#
# Delete all cookies
#
def delete_all_cookies
@bridge.delete_all_cookies
end
#
# Get all cookies
#
# @return [Array<Hash>] list of cookies
#
View on GitHub (pinned to aa36b38e69)
Solutions
- Ensure the name variable is a non-empty String before calling delete_cookie.
- Filter blank entries from the name list: names.compact.reject(&:empty?).
- Default to a guard clause: next if name.nil? || name.strip.empty?
Example fix
# before driver.manage.delete_cookie(name) # name may be nil # after if name && !name.to_s.strip.empty? driver.manage.delete_cookie(name) end
Defensive patterns
Strategy: validation
Validate before calling
next if name.nil? || name.to_s.strip.empty? driver.manage.delete_cookie(name)
Type guard
def valid_cookie_name?(name) name.is_a?(String) && !name.strip.empty? end
Try / catch
begin
driver.manage.delete_cookie(name)
rescue ArgumentError => e
raise unless e.message.include?('null or empty')
# skip or log; name was invalid
end Prevention
- Sanitize the name list with compact and reject(&:strip!.!) before looping.
- Guard UI-derived names with a presence check.
- Treat nil/blank names as no-ops in deletion loops.
When it happens
Trigger: Calling driver.manage.delete_cookie(nil). Passing an empty string delete_cookie('') or whitespace delete_cookie(' '). Reading a name from a variable that resolved to nil.
Common situations: Looping over a list of names that contains nil/blank entries. UI-driven input that yields an empty cookie name. Forgetting to check user input before deletion.
Related errors
- name is required
- Params must be an instance of CookieFilter. Received:'${cook
- Cookie name cannot be empty
- invalid value for expiration date: #{obj.inspect}
- Invalid page size: #{value}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/17ac80dcdc136ac9.
Report an issue: GitHub.