V
V
vlarkanov2020-01-23 14:40:32
linux
vlarkanov, 2020-01-23 14:40:32

Python: how to get a screenshot of the entire page?

Hello.
Here is my code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get(URL)
filename = "screenshots/" + filename_prefix + "-" + get_timestamp() + ".png"
print("Saving " + filename)
element = driver.find_element_by_tag_name('body')
element.screenshot(filename)
driver.quit()

Using
element = driver.find_element_by_tag_name('body')
element.screenshot(filename)

i'm trying to get the whole page to be screened, but i get only part of it, as if i use
driver.get_screenshot_as_file(filename)
what i'm doing wrong? I looked at the page, all the necessary information is within the body tag.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-01-23
@vlarkanov

driver.set_window_size to match the height or even more of your body

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question