Unable to login to a site with casperjs

1,100 views
Skip to first unread message

Philippe Fremy

unread,
May 30, 2013, 10:21:08 AM5/30/13
to casp...@googlegroups.com
Hi,

I must be missing something very basic because I am unable to login to a site with casperjs.


No javascript, just basic HTML and two hidden form values.

My script is basically :
casper.open(URL_REPORTS_EPG_FR).then( function login() {
    this.fill( 'form#Form1', {
        'TxtUser': USER,
        'TxtPwd': PWD,
    }, true);
    utils.dump( this.getFormValues('form') );
});

When I run the script, I get :
[info] [phantom] Starting...
[debug] [phantom] opening url: https://fr.parxglobal-hl.com/EasyParkReports/Logon.aspx, HTTP GET
[debug] [phantom] Navigation requested: url=https://fr.parxglobal-hl.com/EasyParkReports/Logon.aspx, type=Other, lock=true, isMainFrame=true
[info] [phantom] Running suite: 2 steps
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 1/2 https://fr.parxglobal-hl.com/EasyParkReports/Logon.aspx (HTTP 200)
[info] [remote] attempting to fetch form element from selector: 'form#Form1'
[debug] [remote] Set "TxtUser" field value to XXXXX
[debug] [remote] Set "TxtPwd" field value to *****
[info] [remote] submitting form to Logon.aspx, HTTP POST
{
    "BtnLogon": "Connexion",
    "TxtPwd": "XXXXX",
    "TxtUser": "XXXXX",
    "__EVENTVALIDATION": "/wEWBAKN16vPBwKh4tiHDgL9grudDgKE27qFCdW145bCpO7ou3jWF9Bs7B+Hh3KK",
    "__VIEWSTATE": "/wEPDwUKLTExMjk0NjMxMg9kFgICAw9kFgoCAQ8PFgIeBFRleHQFN1ZldWlsbGV6IGVudHJlciB1biBub20gZCd1dGlsaXNhdGV1ciBldCB1biBtb3QgZGUgcGFzc2VkZAIDDw8WAh8ABRIocmV2LiAxMDYyMCBENy4xMylkZAIFDw8WAh8ABQxVdGlsaXNhdGV1cjpkZAIJDw8WAh8ABQ5Nb3QgZGUgcGFzc2UgOmRkAg0PDxYCHwAFCUNvbm5leGlvbmRkZDNWL+phDrTg97/SnItKzEUdMZnW"
}
[info] [phantom] Step 1/2: done in 1307ms.
[debug] [phantom] Navigation requested: url=https://fr.parxglobal-hl.com/EasyParkReports/Logon.aspx, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 https://fr.parxglobal-hl.com/EasyParkReports/Logon.aspx (HTTP 200)
[debug] [phantom] Capturing page to W:/parx/EasyPark/Software Projects/stats_reports/piafstat/casper_scripts/screenshot.png with clipRect {"top":0,"left":0,"width":1024,"height":1024}
[info] [phantom] Capture saved to W:/parx/EasyPark/Software Projects/stats_reports/piafstat/casper_scripts/screenshot.png
Title: Rapports Piaf
[info] [phantom] Step 2/2: done in 1999ms.
[info] [phantom] Done 2 steps in 2000ms


It does not work because I am redirected to the same Logon page, whereas if I login with a browser, I am redirected to a different page.

I tried to login with wrong user/password, I am redirected to the same page, without any error message. If I enter a wrong user/password with a regular browser, I do get an error message (see two screenshots attached).

I check the form content and it does correclty contain the hiden form values.

Any idea of what I am doing wrong ?


cheers,

Philippe



screenshot-google-crhome-with-wrong-login-pwd.png
screenshot-casperjs-with-wrong-login-pwd.png

enabl...@gmail.com

unread,
Jul 26, 2013, 2:57:07 AM7/26/13
to casp...@googlegroups.com
Hi...i am also stuck at login page...were you able to find the solution for your problem ?

Robert Igl

unread,
Jul 26, 2013, 10:13:54 AM7/26/13
to casp...@googlegroups.com
Try not to use the submit (via true in the fill) but trigger a thenClick after it on the button ;)
If you have some Ajaxrequest after that just put another
casper.then(function{
    this.waitForSelector('selector');
)}
around it to be sure the next page is loaded
Hope this will help
Message has been deleted

Vladimir Cacic

unread,
Feb 6, 2016, 5:52:42 PM2/6/16
to CasperJS
Hi you can use something like this

// Start Login

casper.start(startUrl, function() {

    this.evaluate(function() {

        document.querySelector('input#loginpassfield').value = 'PASSWORD';

        document.querySelector('input#loginuserfield').value = 'USER';

        document.querySelector('input#button').click();

    });

    casper.capture('screen/FirstPageWithTextInForm1.png');

 

});

And then wait element to show

//Start loading app page

casper.waitWhileSelector('form', function(){
//do your things
})

Reply all
Reply to author
Forward
0 new messages