diff --git a/ufo/automator/ui_control/screenshot.py b/ufo/automator/ui_control/screenshot.py index 34af17ee..12f25384 100644 --- a/ufo/automator/ui_control/screenshot.py +++ b/ufo/automator/ui_control/screenshot.py @@ -79,12 +79,17 @@ def __init__(self, control: UIAWrapper): """ self.control = control - def capture(self, save_path: str = None, scalar: List[int] = None) -> Image.Image: + def capture(self, save_path: str = None, scalar: List[int] = None) -> Optional[Image.Image]: """ Capture a screenshot. :param save_path: The path to save the screenshot. - :return: The screenshot. + :param scalar: Optional rescale dimensions [width, height]. + :return: The screenshot, or None if the control is unavailable. """ + if self.control is None: + logger.warning("Cannot capture screenshot: control element is None.") + return None + # Capture single window screenshot screenshot = self.control.capture_as_image() if scalar is not None: