Created
July 11, 2014 20:31
-
-
Save cburgmer/caa1ab22de50ca6276d6 to your computer and use it in GitHub Desktop.
Take a screenshot with selenium from node
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
npm install selenium-webdriver | |
npm install selenium-server-standalone-jar | |
npm install phantomjs |
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
var fs = require('fs'); | |
var jar = require('selenium-server-standalone-jar'); | |
console.log(jar.path); | |
console.log(jar.version); | |
var webdriver = require('selenium-webdriver'), | |
SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; | |
var server = new SeleniumServer(jar.path, { | |
port: 4444 | |
}); | |
server.start(); | |
var driver = new webdriver.Builder(). | |
usingServer(server.address()). | |
// withCapabilities(webdriver.Capabilities.firefox()). | |
withCapabilities(webdriver.Capabilities.phantomjs()). | |
build(); | |
driver.get('http://twitter.com'); | |
driver.takeScreenshot().then(function (base64Image) { | |
var decodedImage = new Buffer(base64Image, 'base64'); | |
fs.writeFile('image_decoded.jpg', decodedImage, function(err) {}); | |
console.log('took screenshot'); | |
}); | |
driver.quit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know its very old... but
How you handle this?
WebDriverError: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html