在页面上有一个链接:
<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();
在页面上有一个链接:
<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();
另请参阅 casperjs 中有关以下内容的文档:
casper.waitForPopup();
casper.withPopup();
新窗口(单击带有 target="_blank" 属性的链接时)可以被视为弹出窗口。
文档位于:http ://docs.casperjs.org/en/latest/modules/casper.html#waitforpopup
CasperJS 不适用于新窗口。在单击链接之前,您必须手动删除“target=_blank”:
this.evaluate(function () {
[].forEach.call(__utils__.findAll('a'), function(link) {
link.removeAttribute('target');
});
});
casper.start('http://domain.com');
casper.thenClick('#quote');
casper.waitForResource('file1.png' , function() {
this.capture('file1.png');
});
casper.run();
您应该尝试等待所有资源加载完毕,然后继续其他作业。这将始终有效。