2015-12-04 57 views
0

我試圖使用casper登錄到http://insider.espn.go.com/insider/pickcenter/。 現在的問題是,當你點擊登錄按鈕,一個AngularJS生成的文件 - 用戶名和密碼出現。 我已經把WaitForSelector等待這個彈出窗口。但它總是退出說「超時過期」使用Casper以Javascript生成的內容登錄頁面

這是我的腳本。請幫忙。

var links = []; 
var casper = require("casper").create(); 

function getLinks() { 
    var links = document.querySelectorAll('a'); 
    return Array.prototype.map.call(links, function(e) { 
     return e.getAttribute('href'); 
    }); 
} 
casper.on('page.loaded', function() { 
    this.echo('page title is ' + this.getTitle()); 
}); 
casper.start('http://insider.espn.go.com/insider/pickcenter/', function() { 
    // search for 'casperjs' from google form 
    this.emit('page.loaded'); 
    casper.capture('test1.png'); 
    this.click('#ins_signin'); 

}); 
casper.wait(5000,function(){ 
    casper.capture('test2.png') 
}); 
casper.wait(5000,function(){ 
    casper.capture('test3.png') 
}); 
casper.waitForSelector(".ng-scope", function() { 
    this.echo('Login Modal Active!'); 
    casper.capture('test4.png'); 
    //this.capture('screenshotofmodal.png', { top: 0, left:0, width:1000, height: 4000}); 

}); 

casper.then(function() { 
this.fill('input[id="username"]', { q: 'removed' }, true); 
    this.fill('input[id="passwordfield"]', { q: 'removed' }, true); 

}); 
casper.then(function() { 

    this.click('#submitBtn'); 
}); 
casper.then(function() { 
    // aggregate results for the 'phantomjs' search 
    links = links.concat(this.evaluate(getLinks)); 
}); 

casper.run(function() { 
    // echo results in some pretty fashion 
    this.echo(links.length + ' links found:'); 
    this.echo(' - ' + links.join('\n - ')).exit(); 
}); 

回答

0

首先,點擊之前,我想補充檢查,以驗證該按鈕被加載。之後,我會將註冊表單固定在唯一的選擇器上。在頁面上快速查看後,當您單擊登錄時,電子郵件輸入會有一個「ng-touched」類,只有在點擊註冊後纔會出現。我會嘗試是這樣的:

casper.start('http://insider.espn.go.com/insider/pickcenter/', function() { 
    // search for 'casperjs' from google form 
    this.emit('page.loaded'); 
    casper.capture('test1.png'); 
}); 
casper.waitForSelector("#ins_signin",function then(){ 
    this.click("#ins_signin"); 
}, function onTimeOut(){ 
    this.capture('waitSignInFail.png'); 
}, 5000); 

casper.waitForSelector(".ng-touched", function then() { 
    this.echo('Login Modal Active!'); 
    casper.capture('weHaveSignInForm.png'); 
}, function onTimeOut(){ 
    this.capture('signInFormFail.png'); 
}, 5000); 
+0

我不能在您的文章,所以我不得不回答甚至儘管我對你問題的時候了,所以我會在這裏問他們,希望你看到它的評論。什麼test2.png呈現給你,與您的初始代碼張貼? –