Home > Net >  Selenium screenshot of multiple elements
Selenium screenshot of multiple elements

Time:11-23

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?

CodePudding user response:

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 = 'https://www.startech.com.bd/benq-gw2480-fhd-monitor'
browser.get(url) 
browser.execute_script('window.scrollBy(0, 100);')
elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//section[@id='specification']")))
elem.screenshot('fullspec.png')

print('screenshotted specs')

Se Selenium documentation here.

  • Related