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.
casper.open(URL_REPORTS_EPG_FR).then( function login() {
this.fill( 'form#Form1', {
'TxtUser': USER,
'TxtPwd': PWD,
}, true);
utils.dump( this.getFormValues('form') );
});
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] Successfully injected Casper client-side utilities
[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] Successfully injected Casper client-side utilities
[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.