Search code examples
javascriptazurephantomjscasperjs

CasperJs email is not valid on textbox


Im using phantomjs and casperjs to login to azure. One issue im facing is that on the login page it enters my email and its complaining that the email isn't valid.

Anyone have any ideas why?

enter image description here

console.log("got here");
var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
    console.log(msg);
};

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';
page.open("https://login.microsoftonline.com/d05954c1-36eb-40b2-8f23-7f2ce352faf6/oauth2/authorize?response_type=code+id_token&client_id=4c011fb8-5afd-4a16-9283-8bee6e25cb33&redirect_uri=https%3A%2F%2Fanalytics.applicationinsights.io%2Fsubscriptions%2F3a0b2801-2ab5-4b2d-8ce7-426aa48f826f%2Fresourcegroups%2Fp17us1ops001-rg%2Fcomponents%2Fp17us1app-insights001&state=097bcf2a-dfa5-4a57-ab04-502c38573de9&client-request-id=46177667-a6bd-4a76-9e7d-b17383ead80a&x-client-SKU=Js&x-client-Ver=1.0.13&nonce=8e26091b-137d-4b24-826d-6410d1145289&resource=https%3A%2F%2Fmanagement.core.windows.net%2F", function(status) {
    console.log("azure website opened");

    if ( status === "success" ) {
        page.evaluate(function() {

              document.querySelector("input[id='i0116']").value = '[email protected]';    
              document.querySelector('input[id="idSIButton9"]').click();
              document.querySelector("input[id='i0118']").value = "mysecurePassword";


              console.log("Login submitted!");
        });
        window.setTimeout(function () {
          page.render('final.png');
          phantom.exit();
        }, 5000);
   }
});

Solution

  • The issue is that application doesn't recognise your input change. Use built-in functions to send value to input. Since you have casperjs tag in your question I will provide you casperjs solution.

    var casper = require('casper').create({
      viewportSize: {
          width: 1200,
          height: 800
      },
    });
    casper
    .start()
    .thenOpen("https://login.microsoftonline.com", function () {
      this.echo('Opened it');
    })
    .then(function() {
      this.sendKeys('input[type=email]', 'youremail');
    })
    .thenClick('input[type=submit]')
    .wait(5000)
    .then(function() {
      this.capture('test.png');
    })
    .run();
    

    This will bring you to next screen(the password screen) so you can do your magic there.