public
Last active

Save a screenshot with selenium-webdriver for JavaScript

  • Download Gist
screenshot.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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
driver.saveScreenshot('mypage.png');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.