SeleniumHQ/selenium · error · ArgumentError
Invalid page size: #{value}
Error message
Invalid page size: #{value} What it means
PrintOptions#page_size= accepts a Symbol naming a predefined paper size (:letter, :legal, :a4, :tabloid). If the Symbol is not one of those keys, ArgumentError is raised. For custom dimensions, pass a Hash with :width and :height instead.
Source
Thrown at rb/lib/selenium/webdriver/common/print_options.rb:78
# Gets the current page size.
#
# @return [Hash] The current page size hash with :width and :height.
attr_reader :page_size
# Sets the page size. Can be a predefined symbol or custom size hash.
#
# @param [Symbol, Hash] value The predefined size (:letter, :legal, :a4, :tabloid) or a custom hash.
def page_size=(value)
predefined_sizes = {
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 one of the predefined Symbols: :letter, :legal, :a4, or :tabloid.
- For any other size, pass a custom Hash: page_size = { width: 29.7, height: 42.0 } (cm).
- Double-check Symbol casing; the keys are lowercase (:a4, not :A4).
Example fix
# before
print_options.page_size = :a3
# after
print_options.page_size = { width: 29.7, height: 42.0 } Defensive patterns
Strategy: validation
Validate before calling
allowed = %i[letter legal a4 tabloid]
raise ArgumentError, "unsupported size #{size}" unless allowed.include?(size) Type guard
def predefined_size?(sym) sym.is_a?(Symbol) && %i[letter legal a4 tabloid].include?(sym) end
Try / catch
begin
print_options.page_size = size
rescue ArgumentError => e
raise unless e.message.include?('Invalid page size')
print_options.page_size = :a4
end Prevention
- Restrict input to the four predefined Symbols or build a custom Hash.
- Normalize user input with .to_s.downcase.to_sym and validate.
- Document supported sizes for any UI that exposes page_size.
When it happens
Trigger: Calling print_options.page_size = :a3 (not predefined). Using an uppercase or misspelled Symbol like :A4 or :leter. Passing a Symbol for a paper size the library does not ship.
Common situations: Assuming a paper size is supported when it is not. Case sensitivity mistakes (:A4 vs :a4). Typos in size names.
Related errors
- Custom page size must include :width and :height
- Page size must be a Symbol or a Hash
- Value of scale should be between 0.1 and 2
- Orientation value must be one of {self.ORIENTATION_VALUES}
- {property_name} cannot be less than 0
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/df6f120da165502e.
Report an issue: GitHub.