SeleniumHQ/selenium · error · ValueError
Value of scale should be between 0.1 and 2
Error message
Value of scale should be between 0.1 and 2
What it means
The scale property on PrintOptions must be a number between 0.1 and 2.0 inclusive. It first validates the value is numeric (via _validate_num_property) and then checks the 0.1–2.0 range, raising ValueError if outside. This maps to the W3C print scale parameter controlling rendering zoom.
Source
Thrown at py/selenium/webdriver/common/print_page_options.py:100
def __set__(self, obj, value) -> None:
getattr(obj, "_validate_num_property")(f"Margin {self.name}", value)
obj._margin[self.name] = value
obj._print_options["margin"] = obj._margin
class _ScaleDescriptor:
"""Scale descriptor which validates scale."""
def __init__(self, name):
self.name = name
def __get__(self, obj, cls) -> float | None:
return obj._print_options.get(self.name)
def __set__(self, obj, value) -> None:
getattr(obj, "_validate_num_property")(self.name, value)
if value < 0.1 or value > 2:
raise ValueError("Value of scale should be between 0.1 and 2")
obj._print_options[self.name] = value
class _PageOrientationDescriptor:
"""PageOrientation descriptor which validates orientation of page."""
ORIENTATION_VALUES = ["portrait", "landscape"]
def __init__(self, name):
self.name = name
def __get__(self, obj, cls) -> Orientation | None:
return obj._print_options.get(self.name, None)
def __set__(self, obj, value) -> None:
if value not in self.ORIENTATION_VALUES:
raise ValueError(f"Orientation value must be one of {self.ORIENTATION_VALUES}")
obj._print_options[self.name] = valueView on GitHub (pinned to aa36b38e69)
Solutions
- Set scale to a float in [0.1, 2.0], e.g. 1.0 for default, 2.0 for double size.
- If you intended a percentage, divide by 100 (clamped to the range).
Example fix
# before print_options.scale = 150 # out of range -> ValueError # after print_options.scale = 1.5
Defensive patterns
Strategy: validation
Validate before calling
if not isinstance(scale, (int, float)) or scale < 0.1 or scale > 2:
raise ValueError('scale must be a number in [0.1, 2.0]')
print_options.scale = scale Type guard
def is_valid_scale(v) -> bool:
return isinstance(v, (int, float)) and 0.1 <= v <= 2.0 Try / catch
try:
print_options.scale = scale
except ValueError:
print_options.scale = 1.0 # default Prevention
- Remember scale is a multiplier in 0.1–2.0, not a percentage.
- Clamp external input to the range before assigning.
When it happens
Trigger: Setting print_options.scale = 3, print_options.scale = 0, or print_options.scale = 0.05. A non-numeric value raises the earlier 'should be an integer or a float' error first.
Common situations: Assuming scale is a percentage (passing 100 instead of 1.0). Passing 0 to 'disable' scaling. Misreading the spec bounds.
Related errors
- {property_name} cannot be less than 0
- Orientation value must be one of {self.ORIENTATION_VALUES}
- Invalid page size: #{value}
- Custom page size must include :width and :height
- Unexpected compiled output format. Expected it to start with
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/61cb244583a4bd3b.
Report an issue: GitHub.