Hey I am trying to take a screenshot of an element with nightmare and than I want to extract text from this screenshot with a function and use the result of this in nightmare.type()
. The Problem is when I use nightmare.run()
I get an error that the screenshot does not exist. How can I fix this? This is my code:
var Nightmare = require('nightmare');
var Screenshot = require('nightmare-screenshot');
var nightmare = new Nightmare();
nightmare.goto('website');
//Takes screenshot of element
nightmare.use(Screenshot.screenshotSelector('screenshot' + i + '.png', 'img[id="yw0"]'));
nightmare.type('input[id=AuthForm_login]', username);
nightmare.type('input[id=AuthForm_password]', password);
nightmare.type('input[id=upload]', image.decodeFile('screenshot' + i + '.png', function(err, result){
//Returns Text from the Screenshot taken above!
return result.text;
}));
nightmare.run();
When I remove the line:
nightmare.type('input[id=upload]', image.decodeFile('screenshot' + i + '.png', function(err, result){
//Returns Text from the Screenshot taken above!
return result.text;
}));
Everything works fine and I get a screenshot.