splinter icon indicating copy to clipboard operation
splinter copied to clipboard

element screenshot code needs correction

Open sdmovie opened this issue 8 years ago • 1 comments

In splinter ->driver->webdriver->init.py, line 799 ###original code ratio = im_width * 1.0 / window_width height_ratio = im_height / ratio

    im = im.resize((int(window_width), int(height_ratio)))

    location = self._element.location
    x, y = location['x'], location['y']

    pic_size = self._element.size
    w, h = pic_size['width'], pic_size['height']
    box = x, y, x + w, y + h
    #box = x, y, x + w, y + h
    box = [int(i) for i in box]
    target = im.crop(box)

############################# there was a by-ratio image processing that suppose to crop correct element screenshot from a window screen shot. Maybe there was history issues that lead to the fix. However , this do not work well when I am using up-to-date (chrome driver version 2.44,2.43,2.42, I did not try even earlier ones), cropped image is shifted toward right-bottom corner , in my case losing its' left 5 or 3 pixel lines and top 3 or 5 pixel line (depending on using full=True or not), and respectively the right and bottom lines.image size remains.

While debugged into code, found the driver captured window screenshot(aka the "im" in code is already the canvas part,no menu, no boundary. Thus , just clean the processing code, use as-is crop get the perfect element screenshot, code replacing block above:

    location = self._element.location
    x, y = location['x'], location['y']

    pic_size = self._element.size
    w, h = pic_size['width'], pic_size['height']
    box = x, y, x + w, y + h
    box = [int(i) for i in box]
    target = im.crop(box)

python3 on win10 , 64bit.chrome driver

sdmovie avatar Nov 26 '18 13:11 sdmovie

Fixed by #1020

javascript-error avatar Apr 03 '22 19:04 javascript-error