def save_as_png ( self , filename , width = 300 , height = 250 , render_time = 1 ) : self . driver . set_window_size ( width , height ) self . driver . get ( 'file://{path}/{filename}' . format ( path = os . getcwd ( ) , filename = filename + ".html" ) ) time . sleep ( render_time ) self . driver . save_screenshot ( filename + ".png" )
take a screenshot python webdriver
Open saved html file in an virtual browser and save a screen shot to PNG format .
def save_as_png(self, filename, width=300, height=250, render_time=1):
        """Open saved html file in an virtual browser and save a screen shot to PNG format."""
        self.driver.set_window_size(width, height)
        self.driver.get('file://{path}/{filename}'.format(
            path=os.getcwd(), filename=filename + ".html"))
        time.sleep(render_time)
        self.driver.save_screenshot(filename + ".png")