Skip to content

Commit

Permalink
add fallback for screenshot (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue authored Aug 9, 2024
1 parent 2267dbf commit c099bbc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c099bbc

Please sign in to comment.