Have a look at SIKULI.
Sikuli is a visual technology to automate and test graphical user
interfaces (GUI) using images (screenshots).
SIKULI uses a very clever combination of taking screenshots, and embedding them into your python (it’s jython, actually) script.
Take screenshots:
and use them in your code: