Created
November 26, 2013 12:59
-
-
Save thekarel/7657903 to your computer and use it in GitHub Desktop.
Selenium webdriver JS take screenshot -- from http://stackoverflow.com/questions/15902142/webdriverjs-selenium2-from-nodejs-correct-syntax-for-taking-screenshot
This file contains 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
function writeScreenshot(data, name) { | |
name = name || 'ss.png'; | |
var screenshotPath = 'C:\\selenium_local_map\\'; | |
fs.writeFileSync(screenshotPath + name, data, 'base64'); | |
}; | |
driver.takeScreenshot().then(function(data) { | |
writeScreenshot(data, 'out1.png'); | |
}); |
It's not working anymore:
Failed: ENOENT: no such file or directory, open './screenshots/out1.png'
And from the comment:
browser.saveScreenshot() - that's a method from webdriver.io, not present in Selenium webdriver.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for making this
Another way to do it, from the docs
var screenshot = browser.saveScreenshot(); // returns base64 string buffer
fs.writeFileSync('./myShort.png', screenshot)