Casperjs和waitForUrl()等待下一页 [英] Casperjs and waitForUrl() to wait for next page

查看:115
本文介绍了Casperjs和waitForUrl()等待下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 http中的waitForUrl()函数://docs.casperjs.org/en/latest/modules/casper.html#waitforurl .发送登录表单后,casperjs应等待下一页加载.在下面的代码中,您将看到第二种变体",这是我尝试对此进行编码的方式,并且还看到了发生的错误消息. 第一个变体"正在运行,因此可以捕获dashboard.png.

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

推荐答案

我明白了!

第二个变体"不是问题.在此之前的登录步骤会导致错误.对于正确的登录步骤,我需要等待一秒钟,以便casperjs设置cookie.

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.

我还更改了填写表格发送方式的方式.通过以下登录步骤,带有waitForUrl()的第二个变体"可以正常工作:

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

此外,以下警告消失了!因此,这可能意味着,每当您收到此警告而您不知道为什么时,就去检查一下Cookie:

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

这篇关于Casperjs和waitForUrl()等待下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆