{"record":{"id":"5bfe9b7773230cc4","repo":"SeleniumHQ/selenium","slug":"you-can-only-set-the-orientation-to-landscape-an","errorCode":null,"errorMessage":"You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'","messagePattern":"You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'","errorType":"validation","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1142,"sourceCode":"            `orientation = driver.orientation`\n        \"\"\"\n        return self.execute(Command.GET_SCREEN_ORIENTATION)[\"value\"]\n\n    @orientation.setter\n    def orientation(self, value) -> None:\n        \"\"\"Sets the current orientation of the device.\n\n        Args:\n            value: Orientation to set it to.\n\n        Example:\n            `driver.orientation = \"landscape\"`\n        \"\"\"\n        allowed_values = [\"LANDSCAPE\", \"PORTRAIT\"]\n        if value.upper() in allowed_values:\n            self.execute(Command.SET_SCREEN_ORIENTATION, {\"orientation\": value})\n        else:\n            raise WebDriverException(\"You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'\")\n\n    def start_devtools(self) -> tuple[Any, WebSocketConnection]:\n        global cdp\n        import_cdp()\n        if self.caps.get(\"se:cdp\"):\n            ws_url = self.caps.get(\"se:cdp\")\n            cdp_version = self.caps.get(\"se:cdpVersion\")\n            if cdp_version is None:\n                raise WebDriverException(\"CDP version not found in capabilities\")\n            version = cdp_version.split(\".\")[0]\n        else:\n            version, ws_url = self._get_cdp_details()\n\n        if not ws_url:\n            raise WebDriverException(\"Unable to find url to connect to from capabilities\")\n\n        if cdp is None:\n            raise WebDriverException(\"CDP module not loaded\")","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1124-L1160","documentation":"Raised by the orientation setter when value (after .upper()) is not one of the two W3C screen-orientation values LANDSCAPE or PORTRAIT. The setter compares the uppercased string against an allow-list and forwards only valid values to the SET_SCREEN_ORIENTATION command. Note: the comparison is case-insensitive, so 'landscape' is accepted; anything else is rejected.","triggerScenarios":"Calling driver.orientation = 'sideways', 'horizontal', '', or any string whose upper() is not LANDSCAPE/PORTRAIT. Note: passing None raises AttributeError on .upper() before reaching this message, so this message specifically requires a non-LANDSCAPE/PORTRAIT string.","commonSituations":"A developer guesses an orientation name ('horizontal', 'vertical', 'square') instead of the W3C constants. Or passes a user-supplied string without normalizing it first.","solutions":["Use one of the two allowed values: driver.orientation = 'LANDSCAPE' or 'PORTRAIT' (case-insensitive).","Normalize external input by upper-casing and mapping synonyms to LANDSCAPE/PORTRAIT before assignment.","Guard against None/non-string inputs before calling the setter."],"exampleFix":"# before\ndriver.orientation = 'horizontal'\n\n# after\ndriver.orientation = 'LANDSCAPE'","handlingStrategy":"validation","validationCode":"allowed = {'LANDSCAPE', 'PORTRAIT'}\nif not isinstance(value, str) or value.upper() not in allowed:\n    raise ValueError(f'orientation must be one of {allowed}')\ndriver.orientation = value","typeGuard":"def is_valid_orientation(v) -> bool:\n    return isinstance(v, str) and v.upper() in {'LANDSCAPE', 'PORTRAIT'}","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    driver.orientation = value\nexcept WebDriverException:\n    driver.orientation = 'PORTRAIT'  # safe default","preventionTips":["Normalize input with .upper() and validate against LANDSCAPE/PORTRAIT.","Reject None/non-string before calling the setter.","Map UI synonyms to the two W3C constants at your config layer."],"tags":["orientation","mobile","argument-validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}