简体   繁体   English

Casperjs和waitForUrl()等待下一页

[英]Casperjs and waitForUrl() to wait for next page

I'd like to use the waitForUrl() function from http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl . 我想使用http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl中的waitForUrl()函数。 After a login form was send casperjs should wait for the next page is loaded. 发送登录表单后,casperjs应等待下一页加载。 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. “第一个变体”正在运行,因此捕获了dashboard.png。

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');
    });

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. 对于正确的登录步骤,我需要等待一秒钟,以便casperjs设置cookie。

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: 通过以下登录步骤,带有waitForUrl()的“第二个变体”可以正常工作:

// 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: 因此,这可能意味着,每次收到此警告而您不知道为什么时,就去检查一下Cookie:

[warning] [phantom] Loading resource failed with status=fail: http://mytestdomain.de

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM