SeleniumHQ/selenium · error · ValueError

Element Scroll Behavior out of range.

Error message

Element Scroll Behavior out of range.

What it means

Raised as ValueError specifically when setting elementScrollBehavior to a value that is not ElementScrollBehavior.TOP (0) or ElementScrollBehavior.BOTTOM (1). This is a range/enum validation layered on top of the type check — even a correct int type will be rejected if it is outside the two valid enum values.

Source

Thrown at py/selenium/webdriver/ie/options.py:83

        dictionary in `Options` class.
    """

    def __init__(self, name, expected_type):
        self.name = name
        self.expected_type = expected_type

    def __get__(self, obj, cls):
        return obj._options.get(self.name)

    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__}")

        if self.name == "elementScrollBehavior" and value not in [
            ElementScrollBehavior.TOP,
            ElementScrollBehavior.BOTTOM,
        ]:
            raise ValueError("Element Scroll Behavior out of range.")
        obj._options[self.name] = value


class Options(ArgOptions):
    KEY = "se:ieOptions"
    SWITCHES = "ie.browserCommandLineSwitches"

    BROWSER_ATTACH_TIMEOUT = "browserAttachTimeout"
    ELEMENT_SCROLL_BEHAVIOR = "elementScrollBehavior"
    ENSURE_CLEAN_SESSION = "ie.ensureCleanSession"
    FILE_UPLOAD_DIALOG_TIMEOUT = "ie.fileUploadDialogTimeout"
    FORCE_CREATE_PROCESS_API = "ie.forceCreateProcessApi"
    FORCE_SHELL_WINDOWS_API = "ie.forceShellWindowsApi"
    FULL_PAGE_SCREENSHOT = "ie.enableFullPageScreenshot"
    IGNORE_PROTECTED_MODE_SETTINGS = "ignoreProtectedModeSettings"
    IGNORE_ZOOM_LEVEL = "ignoreZoomSetting"
    INITIAL_BROWSER_URL = "initialBrowserUrl"
    NATIVE_EVENTS = "nativeEvents"

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use the ElementScrollBehavior enum: from selenium.webdriver.ie.options import ElementScrollBehavior; options.element_scroll_behavior = ElementScrollBehavior.TOP
  2. If using raw ints, restrict to 0 (TOP) or 1 (BOTTOM) only
  3. Check the enum definition to confirm valid values before assignment

Example fix

// before
options.element_scroll_behavior = 2

// after
from selenium.webdriver.ie.options import ElementScrollBehavior
options.element_scroll_behavior = ElementScrollBehavior.TOP
Defensive patterns

Strategy: validation

Validate before calling

from selenium.webdriver.ie.options import ElementScrollBehavior
valid = [ElementScrollBehavior.TOP, ElementScrollBehavior.BOTTOM]
if value not in valid:
    raise ValueError(f'element_scroll_behavior must be one of {valid}')
options.element_scroll_behavior = value

Type guard

from selenium.webdriver.ie.options import ElementScrollBehavior
def is_valid_scroll_behavior(v) -> bool:
    return v in (ElementScrollBehavior.TOP, ElementScrollBehavior.BOTTOM)

Try / catch

try:
    options.element_scroll_behavior = value
except ValueError:
    options.element_scroll_behavior = ElementScrollBehavior.TOP

Prevention

When it happens

Trigger: Assigning options.element_scroll_behavior = 2, options.element_scroll_behavior = -1, or any int other than 0 or 1 triggers the ValueError. The type check passes (it is an int) but the range check fails.

Common situations: Developers who don't know about the ElementScrollBehavior enum and guess integer values. Copying values from documentation that uses a different numbering scheme.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/d0d81362fd93877b. Report an issue: GitHub.