Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Created July 11, 2014 20:31
Show Gist options
  • Save cburgmer/caa1ab22de50ca6276d6 to your computer and use it in GitHub Desktop.
Save cburgmer/caa1ab22de50ca6276d6 to your computer and use it in GitHub Desktop.
Take a screenshot with selenium from node
npm install selenium-webdriver
npm install selenium-server-standalone-jar
npm install phantomjs
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();
@cburgmer
Copy link
Author

var action = new webdriver.ActionSequence(driver);
action.mouseMove(driver.findElement(webdriver.By.css('.a')));
action.perform();

To trigger the :hover

@cburgmer
Copy link
Author

action.mouseMove(driver.findElement(webdriver.By.css('.form-signup-home button'))).mouseDown();

To trigger :active

@fincha
Copy link

fincha commented Feb 16, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment