{"record":{"id":"83d313cc5bba1f99","repo":"SeleniumHQ/selenium","slug":"x-and-y-or-height-and-width-need-values","errorCode":null,"errorMessage":"x and y or height and width need values","messagePattern":"x and y or height and width need values","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1095,"sourceCode":"        Example:\n            `driver.get_window_rect()`\n        \"\"\"\n        return self.execute(Command.GET_WINDOW_RECT)[\"value\"]\n\n    def set_window_rect(self, x=None, y=None, width=None, height=None) -> dict:\n        \"\"\"Set the window's position and size.\n\n        Sets the x, y coordinates and height and width of the current window.\n        This method is only supported for W3C compatible browsers; other browsers\n        should use `set_window_position` and `set_window_size`.\n\n        Example:\n            `driver.set_window_rect(x=10, y=10)`\n            `driver.set_window_rect(width=100, height=200)`\n            `driver.set_window_rect(x=10, y=10, width=100, height=200)`\n        \"\"\"\n        if (x is None and y is None) and (not height and not width):\n            raise InvalidArgumentException(\"x and y or height and width need values\")\n\n        return self.execute(Command.SET_WINDOW_RECT, {\"x\": x, \"y\": y, \"width\": width, \"height\": height})[\"value\"]\n\n    @property\n    def file_detector(self) -> FileDetector:\n        return self._file_detector\n\n    @file_detector.setter\n    def file_detector(self, detector) -> None:\n        \"\"\"Set the file detector for keyboard input.\n\n        By default, this is set to a file detector that does nothing.\n        See FileDetector, LocalFileDetector, and UselessFileDetector.\n\n        Args:\n            detector: The detector to use. Must not be None.\n        \"\"\"\n        if not detector:","sourceCodeStart":1077,"sourceCodeEnd":1113,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1077-L1113","documentation":"Raised by set_window_rect() when no positional/size argument is supplied at all. The method needs at least one of an (x, y) pair or a (height, width) pair to form a valid W3C SET_WINDOW_RECT command; calling it bare is meaningless and the server would reject it, so the client validates upfront. It is an InvalidArgumentException because the caller passed an invalid combination of arguments.","triggerScenarios":"Calling driver.set_window_rect() with no keyword arguments (all of x, y, width, height default to None). The guard is `(x is None and y is None) and (not height and not width)`, so it only fires when BOTH x and y are None AND height and width are falsy (None or 0).","commonSituations":"A developer refactors code and accidentally drops the keyword arguments, or builds the call dynamically from a dict/config that ends up empty. Also triggered when width or height is 0 combined with missing x/y, because `not 0` is True.","solutions":["Pass at least one coordinate pair, e.g. driver.set_window_rect(x=10, y=10), or one size pair, e.g. driver.set_window_rect(width=800, height=600).","If arguments come from a config dict, validate the dict has at least one of the pairs before calling.","Ensure you are not passing 0 as an intentional 'no change' value for width/height — that counts as falsy; use None instead."],"exampleFix":"# before\ndriver.set_window_rect()\n\n# after\ndriver.set_window_rect(x=10, y=10, width=800, height=600)","handlingStrategy":"validation","validationCode":"# Validate before calling set_window_rect\nif all(v is None for v in (x, y)) and not height and not width:\n    raise ValueError('set_window_rect needs an (x,y) or (height,width) pair')\ndriver.set_window_rect(x=x, y=y, width=width, height=height)","typeGuard":null,"tryCatchPattern":"from selenium.common.exceptions import InvalidArgumentException\ntry:\n    driver.set_window_rect(x=x, y=y, width=width, height=height)\nexcept InvalidArgumentException:\n    # fall back to setting size or position separately\n    driver.set_window_size(width or 800, height or 600)","preventionTips":["Always pass at least one coordinate pair or one size pair.","Treat 0 as a real value for width/height only if you also supply x/y, since 0 is falsy.","When building args from config, assert the config is non-empty before the call."],"tags":["window-management","argument-validation","w3c-webdriver"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}