SeleniumHQ/selenium · error · ArgumentError
Page size must be a Symbol or a Hash
Error message
Page size must be a Symbol or a Hash
What it means
page_size= only accepts a Symbol (predefined size) or a Hash (custom size). Any other type — String, Array, Integer, nil — raises ArgumentError. This is the catch-all branch of the case statement after the Symbol and Hash branches.
Source
Thrown at rb/lib/selenium/webdriver/common/print_options.rb:88
letter: {width: 21.59, height: 27.94},
legal: {width: 21.59, height: 35.56},
a4: {width: 21.0, height: 29.7},
tabloid: {width: 27.94, height: 43.18}
}
case value
when Symbol
raise ArgumentError, "Invalid page size: #{value}" unless predefined_sizes.key?(value)
@page_size = predefined_sizes[value]
when Hash
unless value.key?(:width) && value.key?(:height)
raise ArgumentError, 'Custom page size must include :width and :height'
end
@page_size = value
else
raise ArgumentError, 'Page size must be a Symbol or a Hash'
end
end
end
end
end
View on GitHub (pinned to aa36b38e69)
Solutions
- Use a predefined Symbol (:a4) or a Hash ({ width:, height: }).
- Convert incoming data: if it is a String matching a known size, use .to_sym; otherwise build a Hash.
- Avoid passing Arrays or Strings; map them to the supported types first.
Example fix
# before print_options.page_size = 'A4' # after print_options.page_size = :a4
Defensive patterns
Strategy: type-guard
Validate before calling
raise ArgumentError, 'page size must be Symbol or Hash' unless value.is_a?(Symbol) || value.is_a?(Hash)
Type guard
def valid_page_size?(value) value.is_a?(Symbol) || value.is_a?(Hash) end
Try / catch
begin
print_options.page_size = value
rescue ArgumentError => e
raise unless e.message.include?('Symbol or a Hash')
print_options.page_size = value.to_sym
end Prevention
- Map Strings to Symbols (:a4) and Arrays/tuples to Hashes before assignment.
- Reject nil unless you intend to keep the default.
- Keep page-size data typed as Symbol or Hash throughout your config layer.
When it happens
Trigger: Passing a String like page_size = 'A4'. Passing an Array [21, 29]. Passing an Integer or nil.
Common situations: Assuming a String size name is accepted. Providing a tuple/array from external data. Defaulting to nil accidentally.
Related errors
- Invalid page size: #{value}
- Custom page size must include :width and :height
- #{scroll_origin.inspect} isn't a valid ScrollOrigin
- invalid value for expiration date: #{obj.inspect}
- expected String or Symbol, got #{key.inspect}:#{key.class}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/da92ca14cb37a617.
Report an issue: GitHub.