SHARE
TWEET

Untitled

a guest Mar 20th, 2016 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var steps=[];
  2. var testindex = 0;
  3. var loadInProgress = false;
  4. var webPage = require('webpage');
  5. var page = webPage.create();
  6. page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36';
  7. page.settings.javascriptEnabled = true;
  8. page.settings.loadImages = false;//Script is much faster with this field set to false
  9. phantom.cookiesEnabled = true;
  10. phantom.javascriptEnabled = true;
  11.  
  12. //HERE I DEFINE VARIABLES!!!!!!!!!!!!!!!!!!!!!!
  13. var username = "MyUserName";
  14. var password = "MyPassWord";
  15.  
  16. steps = [
  17.     //Step 1 - Open Facebook home page
  18.     function(){
  19.         page.open("https://www.facebook.com/", function(status){
  20.         });
  21.     },
  22.     function(){
  23.     page.evaluate(function(){
  24.       //HERE OCCURS THE PROBLEM ReferenceError: Can't find variable username undefined:3 :6
  25.       console.log(username);
  26.       document.getElementById("email").value = username;
  27.       document.getElementById("pass").value = password;
  28.       document.getElementById("loginbutton").click();
  29.         });
  30.     }
  31. ];
  32.  
  33. //Execute steps one by one
  34. interval = setInterval(executeRequestsStepByStep,100);
  35.  
  36.  
  37. function executeRequestsStepByStep(){
  38.     if (loadInProgress == false && typeof steps[testindex] == "function") {
  39.         steps[testindex]();
  40.         testindex++;
  41.     }
  42.     if (typeof steps[testindex] != "function") {
  43.       //  console.log(page.content)
  44.         console.log("finished");
  45.         page.render('face.png');
  46.         phantom.exit();
  47.     }
  48. }
  49.  
  50.  
  51. page.onLoadStarted = function() {
  52.     loadInProgress = true;
  53. };
  54. page.onLoadFinished = function() {
  55.     loadInProgress = false;
  56. };
  57. page.onConsoleMessage = function(msg) {
  58.     console.log(msg);
  59. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top