Skip to content

Win Screenshot

Type: win-screenshot  ·  Package: Desktop Activities v1.0.8

Takes a screenshot of the whole window or of a specific element and saves it to an image file. Use it to keep evidence of a result (the receipt the application showed) and to diagnose failures: a screenshot in the catch shows you what the application looked like when something went wrong.

It captures the screen area of the selector element or —if you leave it out— of the session’s whole window, and saves it in path.

  • It captures what is visible on screen in that area: it doesn’t bring the window to the front, so if another window covers it, that one shows up in the image. Use Win Focus first if needed.
  • If path ends in .jpg it saves a JPEG; with any other extension, a PNG.
  • It creates the destination folder if needed and overwrites the file if it already exists.
  • Like every capture, it is explicit: it only happens where you place the activity, never automatically on failure.

To capture the whole desktop without a session or selector, use Take Screenshot.

ParameterTypeDefaultDescription
pathstring—Output file path (.png, .jpg). E.g. C:\temp\capture.png.
ParameterTypeDefaultDescription
sessionZoanDesktopSession—Win Attach session. Inside a body it is taken automatically. Required to capture the whole window.
selectorselector—Element to capture. Empty = the session’s whole window. Without a session, the selector must include the window.
timeoutnumber30000Maximum ms to wait for the element (if there is a selector). Empty = the project’s UI timeout or, if not set, 30000.

This activity does not return a value: the image is left in path. If you need the path in a variable, build it in one first and pass it in path.

MessageCause and fix
'session' or 'selector' is required.There is no session (nor body) and no selector: there’s nothing to capture.
'path' is required.The file path is missing.
Element not found with selector {…}.See common errors.
Windows error while copying the screenThe robot has no interactive desktop (Session 0 or locked session). Run it with a robot session.

Capture the window if something fails, for diagnosis:

Try / Catch errorVariable = error
├─ try:
│ Win Click session = app selector = (button "Process")
│ Win Wait For session = app selector = (label "Done") state = visible
└─ catch:
Win Screenshot session = app path = "C:/evidence/error_" + now().ToString("yyyyMMdd_HHmmss") + ".png"
Log level = error message = "Processing failed: " + error.Message

Keep as evidence only the receipt the application shows:

Win Screenshot selector = (panel "Receipt") path = pathJoin(evidenceFolder, invoiceNumber + ".png")