Taking screenshots of tests as they run is a great tool for discovering rendering issues with your pages. However, taking screenshots from SeleniumRC can be a bit hard, especially if you’re using it in a grid or are using a service like ours. Luckily Selenium provides a command that’s perfect for getting past exactly these kinds of configuration problems, `captureScreenshotToString`. It returns a base64 encoded png of the current page, which you can then write to a file on your local machine. Here’s an example in python:
def test_case(self):
browser = self.browser
browser.open("/")
png = browser.capture_screenshot_to_string()
f = open('screenshot.png', 'wb')
f.write(png.decode('base64'))
f.close()
Tune in next week for another Selenium Tip of The Week!
Related posts:
Selenium Tips: Improving your waiting skills
Selenium Tips: Infinite Loops Take Forever

This takes a screenshot of the entire desktop, not the page.
Yup, see our most recent tip of the week for more information.
[...] While our OnDemand will help you record videos of your entire test, sometimes you just want a screenshot. Selenium supports capturing screenshots on remote machines, as Sean discussed in a previous Tip of the Week (Taking ScreenShots on the Server). [...]
So I can’t figure out a way to use ‘captureScreenShotToString’. It doesn’t show up in the selIDE drop-down the way captureScreenShot and CaptureEntirePageScreenshot are. What arguments does it take? Is it still being used?
Also, I’m exporting my scripts into PHP and then running them on bromine. I know that has nothing to do with you, but I’ve been unable to translate your python example into php. I mention this here because your selenium tips have been extremely helpful thus far. :) Cheers
And I thought it is to be used to compare images on application. So you have one copy of encoded String, you capture another run time and compare these two to find if images are same.