问题
I'd like to use the waitForUrl() function from http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl . After a login form was send casperjs should wait for the next page is loaded. In the code below you see the "Second variant" that's the way I try to code this and you also see the occuring error message. The "First variant" is working so the dashboard.png is captured.
Can someone explain what is wrong with the "Second variant"?
// ...
// Type and send login Form
casper.then(function() {
this.evaluate(function(){
$("username").value="admin";
$("password").value="pass#";
$("login").click();
});
});
// First variant (works) -----------------
// casper.then(function() {
// this.clickLabel('Dashboard', 'a');
// });
// Second variant (works not, error) -----------------
// casper.waitForUrl(/\/admin\/index\.php/,function() {
// this.clickLabel('Dashboard', 'a');
//});
// -> [error] [phantom] Wait timeout of 5000ms expired, exiting.
// -> Wait timeout of 5000ms expired, exiting.
casper.then( function(){
this.capture('./dashboard.png');
});
回答1:
I got it!
The "Second variant" was not the issue. The Login Step before that leads to the error. For a proper Login Step I need to wait a second for casperjs to set the cookies.
I also changed the way to fill out end sending the form. With the following Login Step the "Second variant" with the waitForUrl() is working correct:
// Type and send login Form
casper.wait(1000,function(){
this.fill('.tl_login_form', {
username: "admin",
password: "pass#"
},true);
});
In addition the following warning is gone! So that could mean, everytime you got this warning and you do not know why, go and check your cookies:
[warning] [phantom] Loading resource failed with status=fail: http://mytestdomain.de
来源:https://stackoverflow.com/questions/40402888/casperjs-and-waitforurl-to-wait-for-next-page