def save_screenshot(driver, name, folder=None):
if "<STR_LIT:.>" not in name:<EOL><INDENT>name = name + "<STR_LIT>"<EOL><DEDENT>if folder:<EOL><INDENT>abs_path = os.path.abspath('<STR_LIT:.>')<EOL>file_path = abs_path + "<STR_LIT>" % folder<EOL>if not os.path.exists(file_path):<EOL><INDENT>os.makedirs(file_path)<EOL><DEDENT>screenshot_path = "<STR_LIT>" % (file_path, name)<EOL><DEDENT>else:<EOL><INDENT>screenshot_path = name<EOL><DEDENT>try:<EOL><INDENT>element = driver.find_element_by_tag_name('<STR_LIT:body>')<EOL>element_png = element.screenshot_as_png<EOL>with open(screenshot_path, "<STR_LIT:wb>") as file:<EOL><INDENT>file.write(element_png)<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>if driver:<EOL><INDENT>driver.get_screenshot_as_file(screenshot_path)<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>
Saves a screenshot to the current directory (or to a subfolder if provided)
If the folder provided doesn't exist, it will get created.
The screenshot will be in PNG format.