SeleniumHQ/selenium · error · ValueError

{self.name} should be of type {self.expected_type.__name__}

Error message

{self.name} should be of type {self.expected_type.__name__}

What it means

Raised as ValueError by the _IeOptionsDescriptor.__set__ descriptor when the assigned value does not match the expected_type declared for that option. Each IE option (browser_attach_timeout expects int, ensure_clean_session expects bool, etc.) is backed by a descriptor that validates type on assignment, preventing type mismatches from reaching the IE driver where they would cause confusing protocol errors.

Source

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

    When an attribute assignment happens:

    Example:
        `self.browser_attach_timeout` = 30
        `__set__` method sets/updates the value of the key `browserAttachTimeout` in `_options`
        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"

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Convert the value to the expected type before assignment (int(value), bool(value), str(value))
  2. Check the descriptor declaration in ie/options.py to see the expected_type for each option
  3. Use native Python literals of the correct type directly

Example fix

// before
options.browser_attach_timeout = '30'

// after
options.browser_attach_timeout = 30
Defensive patterns

Strategy: type-guard

Validate before calling

value = '30'
options.browser_attach_timeout = int(value)  # convert to expected type before assignment

Type guard

def matches_expected_type(value, expected_type) -> bool:
    return isinstance(value, expected_type)

Try / catch

try:
    options.browser_attach_timeout = value
except ValueError:
    options.browser_attach_timeout = int(value)

Prevention

When it happens

Trigger: Assigning options.browser_attach_timeout = '30' (str instead of int), options.ensure_clean_session = 1 (int instead of bool), or options.initial_browser_url = 123 (int instead of str) triggers the ValueError.

Common situations: Config values deserialized from JSON/YAML that arrive as strings. Integer 0/1 used for boolean options. Env var values that are always strings.

Related errors


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