diff --git a/py/selenium/webdriver/remote/switch_to.py b/py/selenium/webdriver/remote/switch_to.py index 4621b111a24d5..8da7563113189 100644 --- a/py/selenium/webdriver/remote/switch_to.py +++ b/py/selenium/webdriver/remote/switch_to.py @@ -89,8 +89,8 @@ def frame(self, frame_reference: Union[str, int, WebElement]) -> None: except NoSuchElementException: try: frame_reference = self._driver.find_element(By.NAME, frame_reference) - except NoSuchElementException: - raise NoSuchFrameException(frame_reference) + except NoSuchElementException as exc: + raise NoSuchFrameException(frame_reference) from exc self._driver.execute(Command.SWITCH_TO_FRAME, {"id": frame_reference})