Last active
December 5, 2019 16:08
-
-
Save mnpenner/6441147 to your computer and use it in GitHub Desktop.
Save a screenshot with selenium-webdriver for JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@RoakyWood Not really. I can give you a bigger snippet of how you'd use it...
You can find the Selenium documentation here.