Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Save a screenshot with selenium-webdriver for JavaScript
var webdriver = require('selenium-webdriver');
var fs = require('fs');
var driver = new webdriver.Builder().build();
webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
return driver.takeScreenshot().then(function(data) {
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
if(err) throw err;
// example usage

This comment has been minimized.

Copy link

ghost commented Feb 24, 2016

Hi Mark, do you have any other documentation for this function?


This comment has been minimized.

Copy link
Owner Author

mnpenner commented Feb 25, 2016

@RoakyWood Not really. I can give you a bigger snippet of how you'd use it...

var webdriverjs = require("webdriverjs");

var client = webdriverjs.remote({
    logLevel: 'silent'

client.addCommand('waitClick', function(selector, ms) {
    return this.waitFor(selector, ms || 1000, function(err) {
        expect(err, selector);

client.addCommand('waitSetValue', function(selector, value, ms) {
    return this.waitFor(selector, ms || 1000).setValue(selector, value);


You can find the Selenium documentation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.