SeleniumHQ/selenium · error · InvalidArgumentException

x and y or height and width need values

Error message

x and y or height and width need values

What it means

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.

Source

Thrown at py/selenium/webdriver/remote/webdriver.py:1095

        Example:
            `driver.get_window_rect()`
        """
        return self.execute(Command.GET_WINDOW_RECT)["value"]

    def set_window_rect(self, x=None, y=None, width=None, height=None) -> dict:
        """Set the window's position and size.

        Sets the x, y coordinates and height and width of the current window.
        This method is only supported for W3C compatible browsers; other browsers
        should use `set_window_position` and `set_window_size`.

        Example:
            `driver.set_window_rect(x=10, y=10)`
            `driver.set_window_rect(width=100, height=200)`
            `driver.set_window_rect(x=10, y=10, width=100, height=200)`
        """
        if (x is None and y is None) and (not height and not width):
            raise InvalidArgumentException("x and y or height and width need values")

        return self.execute(Command.SET_WINDOW_RECT, {"x": x, "y": y, "width": width, "height": height})["value"]

    @property
    def file_detector(self) -> FileDetector:
        return self._file_detector

    @file_detector.setter
    def file_detector(self, detector) -> None:
        """Set the file detector for keyboard input.

        By default, this is set to a file detector that does nothing.
        See FileDetector, LocalFileDetector, and UselessFileDetector.

        Args:
            detector: The detector to use. Must not be None.
        """
        if not detector:

View on GitHub (pinned to aa36b38e69)

Solutions

  1. 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).
  2. If arguments come from a config dict, validate the dict has at least one of the pairs before calling.
  3. Ensure you are not passing 0 as an intentional 'no change' value for width/height — that counts as falsy; use None instead.

Example fix

# before
driver.set_window_rect()

# after
driver.set_window_rect(x=10, y=10, width=800, height=600)
Defensive patterns

Strategy: validation

Validate before calling

# Validate before calling set_window_rect
if all(v is None for v in (x, y)) and not height and not width:
    raise ValueError('set_window_rect needs an (x,y) or (height,width) pair')
driver.set_window_rect(x=x, y=y, width=width, height=height)

Try / catch

from selenium.common.exceptions import InvalidArgumentException
try:
    driver.set_window_rect(x=x, y=y, width=width, height=height)
except InvalidArgumentException:
    # fall back to setting size or position separately
    driver.set_window_size(width or 800, height or 600)

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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