Casperjs and waitForUrl() to wait for next page

倾然丶 夕夏残阳落幕 提交于 2019-12-25 04:46:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!