{"record":{"id":"d6b3cd3b6b98bbdc","repo":"SeleniumHQ/selenium","slug":"timeouts-can-only-be-an-int-or-a-float","errorCode":null,"errorMessage":"Timeouts can only be an int or a float","messagePattern":"Timeouts can only be an int or a float","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/timeouts.py","lineNumber":91,"sourceCode":"    Note: This does not set the value on the remote end.\n    \"\"\"\n\n    page_load = _TimeoutsDescriptor(\"_page_load\")\n    \"\"\"Number of seconds to wait for the page to load.\n\n    Note: This does not set the value on the remote end.\n    \"\"\"\n\n    script = _TimeoutsDescriptor(\"_script\")\n    \"\"\"Number of seconds to wait for an asynchronous script to finish execution.\n\n    Note: This does not set the value on the remote end.\n    \"\"\"\n\n    def _convert(self, timeout: float) -> int:\n        if isinstance(timeout, (int, float)):\n            return int(float(timeout) * 1000)\n        raise TypeError(\"Timeouts can only be an int or a float\")\n\n    def _to_json(self) -> JSONTimeouts:\n        timeouts: JSONTimeouts = {}\n        if self._implicit_wait:\n            timeouts[\"implicit\"] = self._implicit_wait\n        if self._page_load:\n            timeouts[\"pageLoad\"] = self._page_load\n        if self._script:\n            timeouts[\"script\"] = self._script\n\n        return timeouts\n","sourceCodeStart":73,"sourceCodeEnd":103,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/timeouts.py#L73-L103","documentation":"Raised by Timeouts._convert() when a value assigned to implicit_wait, page_load, or script is neither an int nor a float. _convert multiplies by 1000 to store milliseconds internally, so non-numeric types (strings, None, bool-as-string) are rejected with a TypeError. The check runs both in the constructor and in the descriptor __set__ on every assignment.","triggerScenarios":"Constructing Timeouts(implicit_wait='10'), assigning driver.timeouts.implicit_wait = '5', or passing a string/None from config parsing (e.g. os.getenv returning a string, or a JSON value that was a string instead of a number).","commonSituations":"Reading timeout values from environment variables or config files that yield strings, deserializing JSON where numbers were quoted, passing a timedelta object, or a None default leaking through.","solutions":["Convert config strings to float before passing: Timeouts(implicit_wait=float(value)).","Use numeric literals in code: Timeouts(implicit_wait=10).","Validate/normalize config at load time so timeout values are always numeric.","Guard None values with a sensible numeric default before assignment."],"exampleFix":"# before\nwait = os.getenv('IMPLICIT_WAIT')  # returns '10' (str)\ntimeouts = Timeouts(implicit_wait=wait)  # -> TypeError\n\n# after\nwait = float(os.getenv('IMPLICIT_WAIT', 0))\ntimeouts = Timeouts(implicit_wait=wait)","handlingStrategy":"type-guard","validationCode":"def coerce_timeout(v):\n    if v is None:\n        return 0\n    f = float(v)\n    return f\n\ntimeouts = Timeouts(implicit_wait=coerce_timeout(cfg.get('implicit_wait')))","typeGuard":"def is_numeric_timeout(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)","tryCatchPattern":"from selenium.webdriver.common.timeouts import Timeouts\ntry:\n    t = Timeouts(implicit_wait=raw)\nexcept TypeError as e:\n    if 'Timeouts can only be an int or a float' in str(e):\n        t = Timeouts(implicit_wait=float(raw))","preventionTips":["Normalize config-sourced values to float at load time.","Treat None as 0 rather than passing it through.","Add unit tests asserting timeout setters accept int and float only."],"tags":["timeouts","type-validation","configuration","typeerror"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}