diff --git a/uiautomator2/__init__.py b/uiautomator2/__init__.py index 11e5ebf..36f9671 100644 --- a/uiautomator2/__init__.py +++ b/uiautomator2/__init__.py @@ -252,8 +252,12 @@ def screenshot(self, filename: Optional[str] = None, format="pillow", display_id """ if display_id is None: base64_data = self.jsonrpc.takeScreenshot(1, 80) - jpg_raw = base64.b64decode(base64_data) - pil_img = Image.open(io.BytesIO(jpg_raw)) + # takeScreenshot may return None + if base64_data: + jpg_raw = base64.b64decode(base64_data) + pil_img = Image.open(io.BytesIO(jpg_raw)) + else: + pil_img = self._dev.screenshot(display_id=display_id) else: pil_img = self._dev.screenshot(display_id=display_id)