Skip to content
CodeKruPro

Save a screenshot of one element

Automation taskMediumAsked in: Capgemini, Infosys, TCS, Wipro

A common follow-up: "Can you capture just one element, such as a chart or a button?" Yes: an element can take its own screenshot, which gives a smaller, clearer image for a report.

Take Element Screenshot

Take Element Screenshot

In Selenium 4, you can take a screenshot of a specific element using element.getScreenshotAs().

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Find the leftClick button
  3. Take a screenshot of just that button element
  4. Verify the screenshot was taken

Expected output:

Element screenshot taken: true
Element screenshot has content: true