无法使用casperjs处理弹出式网页

时间:2014-04-15 09:19:35

标签: javascript casperjs

我是casper js的新手。我无法点击叠加页面上的按钮。你能告诉我如何使用casper js处理叠加页面吗?

1 个答案:

答案 0 :(得分:4)

嗯,这些事件可以帮到你:

casper.on('popup.created', function() {
    this.echo("url popup created : " + this.getCurrentUrl(),"INFO");
});

casper.on('popup.loaded', function() {
    this.echo("url popup loaded : " + this.getCurrentUrl(),"INFO");
});

这里有一个例子:

casper.then(function(){
    this.clickLabel("Activate your account");
            // */mail/* = RegExp for the url
    this.waitForPopup(/mail/, function(){
        this.test.pass("popup opened");
    });
    this.withPopup(/mail/, function(){
        this.viewport(1400,800);
        this.test.pass("With Popup");
        //following, a 'wait instruction' because I have a redirection in my popup
        this.waitForSelector(".boxValid", function(){
            this.test.assertSelectorHasText(".boxValid", "Inscription confirmed");
        });
    });
});

要了解它的工作原理,请查看文档。