CasperJs电子邮件在文本框中无效

时间:2018-02-25 14:17:08

标签: javascript azure phantomjs casperjs

我使用phantomjs和casperjs登录到azure。我面临的一个问题是,在登录页面上,它输入了我的电子邮件,并抱怨该电子邮件无效。

任何人都有任何想法?

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 = 'myemail@outlook.com';    
              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);
   }
});

1 个答案:

答案 0 :(得分:1)

问题是应用程序无法识别您的输入更改。使用内置函数将值发送到输入。由于您在问题中有casperjs标记,我将为您提供casperjs解决方案。

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();

这将带您进入下一个屏幕(密码屏幕),这样您就可以在那里发挥你的魔力。