2

在页面上有一个链接:

<a id="quote" href="quote.html" target="_blank">Quote</a>

在 CasperJS 中单击它,但我无法在新窗口中捕获页面。

casper.start('http://domain.com');
casper.thenClick('#quote');
casper.then(function() {
    this.capture('file1.png');
});

casper.run();
4

3 回答 3

4

另请参阅 casperjs 中有关以下内容的文档:

casper.waitForPopup();
casper.withPopup();

新窗口(单击带有 target="_blank" 属性的链接时)可以被视为弹出窗口。

文档位于:http ://docs.casperjs.org/en/latest/modules/casper.html#waitforpopup

于 2014-02-13T07:50:46.200 回答
1

CasperJS 不适用于新窗口。在单击链接之前,您必须手动删除“target=_blank”:

this.evaluate(function () {
    [].forEach.call(__utils__.findAll('a'), function(link) {
        link.removeAttribute('target');
    });
});
于 2013-11-07T10:12:10.483 回答
0
casper.start('http://domain.com');
casper.thenClick('#quote');
casper.waitForResource('file1.png' , function() {
this.capture('file1.png');
});

casper.run();

您应该尝试等待所有资源加载完毕,然后继续其他作业。这将始终有效。

于 2014-02-05T07:51:42.807 回答