I'm new to Phantomjs and JavaScript itself but for some reason I get the error that the variable username can't be found even though I declared it and that it's a global variable.
var page = require('webpage').create();
var system = require("system");
page.open('https://www.facebook.com/login.php?login_attempt/', function(status) {
page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', function () {
var username = "test";
var password = "test";
page.evaluate(function () {
$("#email").val(username);
$("#pass").val(password);
$("#loginbutton").click();
});
page.onLoadFinished = function () {
page.render("after_submit.png");
if (page.url == "https://www.facebook.com/") {
var fs = require('fs');
var path = 'succes.txt';
var content = "Facebook : \n" + username;
fs.write(path, content, 'w');
}
phantom.exit();
};
page.render("before_submit.png");
});
});