From 40209dfb1cc67235cdf92b1a84008e39549b46e0 Mon Sep 17 00:00:00 2001 From: Joshua McKenty Date: Sat, 4 May 2019 17:47:09 -0700 Subject: [PATCH] Fix for miscropping on retina display High resolution displays have more pixels than they ought to - image width and height has to be adjusted by the devicePixelRatio. --- needle/driver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/needle/driver.py b/needle/driver.py index cd10b49..426f38d 100644 --- a/needle/driver.py +++ b/needle/driver.py @@ -61,12 +61,13 @@ def get_screenshot(self): Returns a screenshot of this element as a PIL image. """ d = self.get_dimensions() + devicePixelRatio = int(self._parent.execute_script("return window.devicePixelRatio")) # Cast values to int in order for _ImageCrop not to break d['left'] = int(d['left']) d['top'] = int(d['top']) - d['width'] = int(d['width']) - d['height'] = int(d['height']) + d['width'] = int(d['width']) * devicePixelRatio + d['height'] = int(d['height']) * devicePixelRatio try: # For selenium >= 2.46.1, W3C WebDriver spec drivers (like geckodriver)