Element Screenshot in Selenium (python, ChromeDriver) is cut off at bottom for vertically tall element

36 Views Asked by At

Trying to screenshot an element but the element is vertically tall and it's getting cut off at the bottom. Seems to happen any time I try to screenshot a tall element.

Selenium 4 with python 3.11.6 on Windows 10.

Is this a limitation of element.screenshot()? Or am I missing something? Couldn't find anything in docs or web search.

Tried this code:

from selenium import webdriver
from selenium.webdriver.common.by import By

options_ = webdriver.ChromeOptions().add_argument("--headless=new")
driver = webdriver.Chrome(options=options_)
driver.get("https://afd.calpoly.edu/web/sample-tables")
element = driver.find_element(By.CSS_SELECTOR, "#content > table:nth-child(17)")
element.screenshot("out.png")
driver.close()

Expect the whole element to be captured but instead it gets cut off at the bottom.

Here's what gets captured:

screen capture of element

Here's the full element that should be captured it seems to me (I zoomed it out so I could take a manual screenshot to show):

enter image description here

0

There are 0 best solutions below