Last active
July 12, 2017 13:53
-
-
Save gustavi/e509b36afbf1a477d3ef37daf075b557 to your computer and use it in GitHub Desktop.
Python Patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_first_day_of_week(day): | |
""" | |
Get the first day of week of a datetime (similar with a date). | |
"""" | |
day.replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=day.weekday()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def take_screenshots_of_element(element): | |
""" | |
Take screenshot of an Selenium element (PIL/Pillow required). | |
:param element: Selenium WebElement | |
""" | |
img_name = 'element.png' | |
loc_x = element.location.get('x') | |
loc_y = element.location.get('y') | |
width = element.size.get('width') | |
height = element.size.get('height') | |
driver.get_screenshot_as_file(img_name) | |
img = Image.open(img_name) | |
img = img.crop((loc_x, loc_y, loc_x+width, loc_y+height)) | |
img.save(img_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment