SeleniumHQ/selenium · error · ValueError
Orientation value must be one of {self.ORIENTATION_VALUES}
Error message
Orientation value must be one of {self.ORIENTATION_VALUES} What it means
The orientation property on PrintOptions only accepts 'portrait' or 'landscape' (lowercase). Any other value raises ValueError. The allowed values are stored in ORIENTATION_VALUES and interpolated into the message.
Source
Thrown at py/selenium/webdriver/common/print_page_options.py:117
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] = value
class _ValidateTypeDescriptor:
"""Base Class Descriptor which validates type of any subclass attribute."""
def __init__(self, name, expected_type: type):
self.name = name
self.expected_type = expected_type
def __get__(self, obj, cls):
return obj._print_options.get(self.name, None)
def __set__(self, obj, value) -> None:
if not isinstance(value, self.expected_type):
raise ValueError(f"{self.name} should be of type {self.expected_type.__name__}")
obj._print_options[self.name] = value
View on GitHub (pinned to aa36b38e69)
Solutions
- Use exactly 'portrait' or 'landscape' (lowercase).
- Lowercase external input before assigning: value.lower().
Example fix
# before
print_options.orientation = 'Portrait' # raises ValueError
# after
print_options.orientation = 'portrait'
# or normalize
print_options.orientation = user_input.strip().lower() if user_input.strip().lower() in ('portrait','landscape') else 'portrait' Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'portrait','landscape'}
value = value.strip().lower()
if value not in ALLOWED:
raise ValueError(f'orientation must be one of {sorted(ALLOWED)}')
print_options.orientation = value Type guard
def is_valid_orientation(v: str) -> bool:
return isinstance(v, str) and v.strip().lower() in {'portrait','landscape'} Try / catch
try:
print_options.orientation = value
except ValueError:
print_options.orientation = 'portrait' Prevention
- Lowercase and strip external input before assigning.
- Map synonyms ('vertical'->'portrait') in your config layer.
When it happens
Trigger: Setting print_options.orientation = 'Portrait' (capitalized), 'horizontal', 'vertical', or '0'. The check is case-sensitive lowercase.
Common situations: Capitalizing the value. Using synonyms ('vertical'/'horizontal'). Pulling orientation from an enum or external source with different naming.
Related errors
- Value of scale should be between 0.1 and 2
- {property_name} cannot be less than 0
- 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/1490924d47a2862a.
Report an issue: GitHub.