I'd like to take a screenshot of a Tableau Public visualisation by taking a screenshot of the entire website and cropping it. I'm able to find height and width of my element, but my x and y coordinates are wrong. I assume x = 0 and y = 0 are the coordinates of my element within the iframe, but not the ones within the website.
How do I get the coordinates for the iframe so I can crop my image corectly? At the moment it just crops the left part of the website.
from selenium import webdriver
import time
from PIL import Image
driver = webdriver.Chrome(executable_path=r'C:\Program Files\chromedriver.exe')
# Maximise window and zoom out
driver.get('chrome://settings/')
driver.maximize_window()
driver.execute_script('chrome.settingsPrivate.setDefaultZoom(0.6);')
driver.get("https://public.tableau.com/en-gb/gallery/super-pac-origins?tab=viz-of-the-day&type=viz-of-the-day")
time.sleep(5)
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
element = driver.find_element_by_xpath('//div[@id = "tab-dashboard-region"]')
location = element.location
print(location)
size = element.size
print(size)
# Take a screenshot
driver.save_screenshot("C:\\Desktop\\Images_png\\test1.png")
time.sleep(2)
#Crop image
x = location['x']
y = location['y']
width = location['x']+ size['width']
height = location['y']+ size['height']
im = Image.open("C:\\Desktop\\Images_png\\test1.png")
im = im.crop((int(x), int(y), int(width), int(height)))
im.save("C:\\Desktop\\Images_png\\Crop\\test1.png")
# Close the current tab
driver.close()
Thanks for your help.