Skip to content

Fix Selenium screenshot cropping issue by retrying with larger height #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dataframe_image/converter/browser/selenium_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def screenshot(self, html: str) -> Image:

# temp_img will be deleted after context exit
img = Image.open(temp_img)

# Retry with larger height if the first screenshot is too short
if img.height < required_height:
shortfall = required_height - img.height +200
driver.set_window_size(required_width + 150, required_height + 90 + shortfall)
driver.save_screenshot(str(temp_img))
img = Image.open(temp_img)
try:
temp_dir_obj.cleanup()
except OSError:
Expand Down
Loading