Search code examples
linuxauthenticationcasperjs

Casperjs Login will not work keep getting resubmission error


Here is my test.js file which I execute with command sudo casperjs test test.js > 2.txt:

casper.start('https://www.bt.com/wifi/secure/statuscheck.do', function() {
this.fill('form[name="LoginForm"]', {
   'username': 'LOGIN',
   'password': 'PASS'
}, true); 
});

casper.wait(2000, function() {
    this.echo(this.getHTML());
});

casper.run();

after this I check the html code in 2.txt and I see it is giving me a resubmission error. How can I fix this?


Solution

  • Try setting a user agent, disable web security, and ignore SSL errors under pageSettings.

    Edit: Code is not tested.

    usage: casperjs theFileName.js

    var casper = require('casper').create ({
      waitTimeout: 15000,
      stepTimeout: 15000,
      verbose: true,
      viewportSize: {
        width: 1280,
        height: 960
      },
      pageSettings: {
        "userAgent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10',
        "webSecurityEnabled": false,
        "ignoreSslErrors": true
      },
      onWaitTimeout: function() {
          // casper.capture('./out/wait-timeout:_' + TimeTidy() + '.png');
          // throw new Error stuff;
      },
      onStepTimeout: function() {
          // casper.capture('./out/step-timeout' + TimeTidy() + '.png');
          // throw new Error stuff;
      }
    });
    
    // Vars
    var fs  = require('fs');
    var url = 'https://www.bt.com/wifi/secure/statuscheck.do';
    
    // Start
    casper.start();
    
    casper.thenOpen(url, function() {
      this.evaluate(function() {
        document.getElementById('username').value = 'yourUsername'; //+++ add your username
        document.getElementById('password').value = 'yourPassword'; //+++ add your password
        var loginButton = document.getElementsByClassName('checkbox btn_login');
        loginButton[0].click();
      });
    });
    
    // Wait 2 sec then write to txt file
    casper.then(function() {
      this.wait(2000, function() {
        var myData = this.getHTML();
        fs.write(myData.txt, myData, 'w');
      });
    });
    
    // Executes
    casper.run();