Justina Chen
Justina Chen

Reputation: 1551

CasperJS: Open a new window

Have a link on the page:

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

Click it in CasperJS, but I can't capture the page in new window.

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

casper.run();

Upvotes: 2

Views: 5965

Answers (3)

yoav barnea
yoav barnea

Reputation: 5994

see also the documentation in casperjs about:

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

the new window(when clicking on link with target="_blank" attribute) can be considered as Popup.

document at: http://docs.casperjs.org/en/latest/modules/casper.html#waitforpopup

Upvotes: 4

Shikhar
Shikhar

Reputation: 971

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

casper.run();

You should try to wait for all the resources to be loaded, then proceed with other job. This will always work.

Upvotes: 0

Kevin
Kevin

Reputation: 1000

CasperJS doesn't work with new windows. You have to manually remove the "target=_blank" before cliking on the link :

this.evaluate(function () {
    [].forEach.call(__utils__.findAll('a'), function(link) {
        link.removeAttribute('target');
    });
});

Upvotes: 1

Related Questions