{"record":{"id":"653d9cbf6589bd4b","repo":"SeleniumHQ/selenium","slug":"property-name-should-be-an-integer-or-a-float","errorCode":null,"errorMessage":"{property_name} should be an integer or a float","messagePattern":"(.+?) should be an integer or a float","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/print_page_options.py","lineNumber":361,"sourceCode":"\n        Args:\n            page_size: A dictionary containing 'height' and 'width' keys with\n                respective values in cm.\n\n        Example:\n            self.set_page_size(PageSize.A4)  # A4 predefined size\n            self.set_page_size({\"height\": 15.0, \"width\": 20.0})  # Custom size\n        \"\"\"\n        self._validate_num_property(\"height\", page_size[\"height\"])\n        self._validate_num_property(\"width\", page_size[\"width\"])\n        self._page[\"height\"] = page_size[\"height\"]\n        self._page[\"width\"] = page_size[\"width\"]\n        self._print_options[\"page\"] = self._page\n\n    def _validate_num_property(self, property_name: str, value: float) -> None:\n        \"\"\"Helper function to validate some of the properties.\"\"\"\n        if not isinstance(value, (int, float)):\n            raise ValueError(f\"{property_name} should be an integer or a float\")\n\n        if value < 0:\n            raise ValueError(f\"{property_name} cannot be less than 0\")\n","sourceCodeStart":343,"sourceCodeEnd":365,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/print_page_options.py#L343-L365","documentation":"The _validate_num_property helper checks that a numeric property (page height/width, margins, scale) is an int or float before accepting it. Passing a string, None, or any non-numeric type raises ValueError naming the property. This is the type gate that runs before the range check.","triggerScenarios":"Calling print_options.set_page_size({'height': '29.7', 'width': 21.0}), setting page_height = '10', or set_page_size with string values from config. scale = '1.0' also hits this via the ScaleDescriptor.","commonSituations":"Reading dimensions from JSON/env as strings. Passing measurements with units ('29.7cm'). Forgetting to cast form/config input.","solutions":["Cast values to float before assigning: float(value).","Strip units from strings before conversion."],"exampleFix":"# before\nprint_options.set_page_size({'height': '29.7', 'width': '21.0'})  # str -> ValueError\n\n# after\nprint_options.set_page_size({'height': float('29.7'), 'width': float('21.0')})","handlingStrategy":"validation","validationCode":"def to_number(v):\n    n = float(v)\n    return n\nh = to_number(page_size['height']); w = to_number(page_size['width'])\nprint_options.set_page_size({'height': h, 'width': w})","typeGuard":"def is_number(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    print_options.set_page_size(page_size)\nexcept ValueError:\n    page_size = {k: float(v) for k, v in page_size.items()}\n    print_options.set_page_size(page_size)","preventionTips":["Cast dimension strings to float at the config boundary.","Strip units (e.g. 'cm') before conversion."],"tags":["print","type-validation","numeric"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}