Selenium screenshot of multiple elements

Selenium screenshot of multiple elements

Problem Description:

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?

Solution – 1

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.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.