2017-01-27 5 views
3
casper.thenOpenを(使用しているとき、どのようにセッションを維持しますCasperJSで

casperjsでセッションを維持するには?例えば

var casper = require('casper').create(); 

casper.start('http://chaseonline.com/', function() { 
    this.echo(this.getTitle()); 
    this.evaluate(function() { 
     document.getElementById("userid").value = "[email protected]"; 
     document.getElementById("password").value = "asdf"; 

    }); 
    this.click("#btnSubmit"); 
}); 

casper.thenOpen('http://chaseonline.com/section/1/module/2/abc.jsp', function() { 
    // now this page never loads because the page requires a logged in session 
    // but casperjs doesn't appear to automatically propagate the session 
    this.echo(this.getTitle()); 
}); 

casper.run(); 

答えて

1

セッションはあなたの例ではまだ開いています。おそらくあなたは正しくログインしていないでしょう。
それは段階的に動作するかどうかだろうが(私が見るサイトはあなたの例では一つではないようで、何のログインはありません):

var casper = require('casper').create(); 
var x = require('casper').selectXPath; 

casper.start('http://youraddess.com/', function() { 
    casper.then(function() { 
    casper.waitForSelector(x("xpath_selector")); 
    }); 
    var data = {}; 
    casper.then(function() { 
    data["//input[@id='userid']"] = "[email protected]"; 
    data["//input[@id='password']"] = "asdf"; 
    casper.fillXPath(x("//form[]"), data, false); 
    }); 
    casper.then(function() { 
    casper.click(x("//button[@id='btnSubmit']")); 
    }); 
    casper.then(function() { 
    casper.waitWhileSelector(x("xpath_selector")); 
    }); 
}); 
casper.thenOpen('http://chaseonline.com/section/1/module/2/abc.jsp', function() { 
    // now this page never loads because the page requires a logged in session 
    // but casperjs doesn't appear to automatically propagate the session 
    casper.then(function() { 
    casper.echo(this.getTitle()); 
    casper.capture('test.png'); 
    }); 
}); 

casper.run(); 

セッションは、実行()は常に同じまでです。新しいものを開く可能性はありますが、それは難しいです。

+0

私は実際のURLとログインの詳細を提供できません。ここに詳細があります: –

+0

明らかに、このthenOpen(url)では利用できないログインセッションのようです。 - ログインした後、私はスクリーンショットをキャプチャし、ログインが成功したことを確認します。 - thenOpen(url)をホームページ(認証が必要ない)やgoogle.comなどに変更すると、スクリプトが機能します。つまり、最後のURLのタイトルを表示します –

+0

phantomjsまたはslimerjsを使用していますか?通常、セッションは実行中に格納されて格納されます(casper.run())。 – dasmelch

関連する問題