The main problem is that console.log does not work in evaluate() .
evaluation is only responsible for returning data in the callback.
Currently, the evaluation function follows the .evaluate(fn, args1, args2) format .evaluate(fn, args1, args2) . Therefore, in your case, when your first function returns data, the next one will not.
If you want the header to simply return a value from the function and execute console.log (a nightmare) inside the launch function.
The following are sample code below:
.evaluate( function () { if($('h1.firstHeading').text()) return $('h1.firstHeading').text(); //Get Heading else return "Not in page context"; } ) .run( function (err, nightmare) { if (err) return console.log(err); console.log(nightmare); console.log('Done!'); } );
Hope this helps.! Thanks
source share