[CasperJs] Soumissions form[0]
Bonjour à tous, je dois mettre en place via casperjs une vérification de mes formulaires. le soucis étant que les forms en question ne contiennent aucun id, name ext..
Code:
1 2 3 4 5 6 7
|
<form action="" method="post">
<input name="username" class="inputform" value="" id="User" type="text">
<input name="password" class="inputform" value="" type="password"></td></tr>
<input name="submit" class="BStd" value="Connexion" type="submit">
<span style="color:#FF4444">Identifiant ou mot de passe incorrect !</span>
</form> |
Actuellement j'ai ceci,
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
this.echo("Page Error: " + msg, "ERROR");
});
function doLogin(){
page.evaluate(function(){
var form = document.forms[0];
form.querySelector('input[name="username"]').value = "monidentifiant";
form.querySelector('input[name="password"]').value = "monmotdepasse";
form.submit();
});
}
var url = "http://www.sitepoursidentifier.com/";
casper.start(url, function() {
console.log("page loaded : " + url);
});
casper.onLoadFinished = function(status){
console.log( (!phantom.state ? "no-state" : phantom.state) + ": " + status );
if("status" === "success"){
if( !phantom.state ){
doLogin();
phantom.state = "logged-in";
phantom.exit();
}
}
};
casper.onConsoleMessage = function (message){
console.log("msg: " + message);
};
casper.run(); |
retour depuis le console :
Citation:
Page Error: TypeError: 'null' is not an object (evaluating 'document.getElementById('contentdiv').style')
Je n'ai aucun getElementById dans mon code .... :?