Selenium screenshot of multiple elements


Im using Python Selenium to scrape a website. At some point during the scrape i want to take a screenshot. I only ‘roughly’ want to take a screenshot covering specific WebElements. How do I take a screenshot of section containing multiple WebElements?

Asked By: Bjarke Kingo



To avoid an eventual XY Problem, here is how you can screenshot any particular element you want, with Selenium (Python) – that element can be a div encompassing other elements:

url = ''
browser.execute_script('window.scrollBy(0, 100);')
elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//section[@id='specification']")))

print('screenshotted specs')

Se Selenium documentation here.

Answered By: Barry the Platipus
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.