You can take a screenshot of the entire page, and then crop the image to the desired element:
const fs = require('fs');
const PNG = require('pngjs').PNG;
var elem = element(by.model('model.username'));
promise.all([
elem.getLocation(),
elem.getSize(),
browser.takeScreenshot()
]).then(function(result) {
var src = PNG.sync.read(Buffer.from(result[2], 'base64'));
var dst = new PNG({width: result[1].width, height: result[1].height});
PNG.bitblt(src, dst, result[0].x, result[0].y, dst.width, dst.height, 0, 0);
fs.writeFileSync('out.png', PNG.sync.write(dst));
});
This will display the .png image of the selected item. As indicated below, you need to make sure that the item is on the screen before; which is achievable like this:
var elem = element(by.model('model.username'));
browser.actions().mouseMove(elem).perform();
source
share