def chrome_fullpage_screenshot(self, file, delay=<NUM_LIT:0>):
total_width = self.driver.execute_script("<STR_LIT>")<EOL>total_height = self.driver.execute_script("<STR_LIT>")<EOL>viewport_width = self.driver.execute_script("<STR_LIT>")<EOL>viewport_height = self.driver.execute_script("<STR_LIT>")<EOL>logger.info("<STR_LIT>"<EOL>.format(total_width, total_height, viewport_width, viewport_height))<EOL>rectangles = []<EOL>i = <NUM_LIT:0><EOL>while i < total_height:<EOL><INDENT>ii = <NUM_LIT:0><EOL>top_height = i + viewport_height<EOL>if top_height > total_height:<EOL><INDENT>top_height = total_height<EOL><DEDENT>while ii < total_width:<EOL><INDENT>top_width = ii + viewport_width<EOL>if top_width > total_width:<EOL><INDENT>top_width = total_width<EOL><DEDENT>logger.debug("<STR_LIT>".format(ii, i, top_width, top_height))<EOL>rectangles.append((ii, i, top_width, top_height))<EOL>ii = ii + viewport_width<EOL><DEDENT>i = i + viewport_height<EOL><DEDENT>stitched_image = Image.new('<STR_LIT>', (total_width, total_height))<EOL>previous = None<EOL>part = <NUM_LIT:0><EOL>for rectangle in rectangles:<EOL><INDENT>if previous is not None:<EOL><INDENT>self.driver.execute_script("<STR_LIT>".format(rectangle[<NUM_LIT:0>], rectangle[<NUM_LIT:1>]))<EOL>logger.debug("<STR_LIT>".format(rectangle[<NUM_LIT:0>], rectangle[<NUM_LIT:1>]))<EOL>time.sleep(delay)<EOL><DEDENT>file_name = "<STR_LIT>".format(part)<EOL>logger.debug("<STR_LIT>".format(file_name))<EOL>self.driver.get_screenshot_as_file(file_name)<EOL>screenshot = Image.open(file_name)<EOL>if rectangle[<NUM_LIT:1>] + viewport_height > total_height:<EOL><INDENT>offset = (rectangle[<NUM_LIT:0>], total_height - viewport_height)<EOL><DEDENT>else:<EOL><INDENT>offset = (rectangle[<NUM_LIT:0>], rectangle[<NUM_LIT:1>])<EOL><DEDENT>logger.debug("<STR_LIT>".format(offset[<NUM_LIT:0>], offset[<NUM_LIT:1>]))<EOL>stitched_image.paste(screenshot, offset)<EOL>del screenshot<EOL>os.remove(file_name)<EOL>part = part + <NUM_LIT:1><EOL>previous = rectangle<EOL><DEDENT>stitched_image.save(file)<EOL>logger.info("<STR_LIT>")<EOL>return True<EOL>
Fullscreen workaround for chrome
Source: http://seleniumpythonqa.blogspot.com/2015/08/generate-full-page-screenshot-in-chrome.html