Skip to content


.click() does not work well with popup links #139

starlocke opened this Issue · 9 comments

4 participants


Filed with PhantomJS...

I'm using CasperJS to do my automated testing, and doing the combination (code below) fails in an unexpected way. I was expecting that the last assert to be successful, but it fails since the focused window does not navigate away, and the popup windows is in limbo (it seems unsupported now in PhantomJS).

Clicking through <a target="_blank"> and similar popup-type links should at least throw some kind of Warning, or Exception... at least while we wait for full support as described in comment 3 (open, focus, close, resize, etc) [of the filing with PhantomJS].

casper.then(function() {
  this.test.assertExists(x("//a[text()='Preview']"), 'Preview Btn Exists');"//a[text()='Preview']")); // Does not open a popup (or does not automatically focus on it).
casper.then(function() {
  this.test.assertExist("div.the_preview", 'Looking at preview');
  this.capture('/tmp/foo.png'); // will be looking that the page with the button, unexpectedly, with no warnings.

It looks pretty similar to issue #138
(In my case, using a CSS selector instead of a XPath selector looks like a good workaround).


Hm. That's a good point. I noticed that issue before writing this report, but I was convinced that it was target="_blank" causing the problems, because, I simply removed target="_blank" and everything worked out as expected.

Let's test the same thing, then, but instead of removing target="_blank", add an id="the_link" !


Nothing related to issue #138. Sample test script:

var casper = require('casper').create();


casper.then(function() { = '<a href="">Google</a>';

casper.then(function() {
    this.test.assertTitle('Google', "I've loaded Google"); = '<a href="" target="_blank">Google</a>';

casper.then(function() {
    this.test.assertTitle('Google', "I've loaded Google");
}); {


$ casperjs t.js
PASS I've loaded Google
FAIL I've loaded Google
#    type: assertTitle
#    details: Page title is not the one expected
#    subject: ""
#    expected: "Google"
FAIL 2 tests executed, 1 passed, 1 failed.                                      

Details for the 1 failed test:

In null:0
   assertTitle: I've loaded Google

This will be solved only when phantomjs will fix indeed.


@n1k0 Nice analysis and test-case! Good job.

@n1k0 n1k0 was assigned
@tlrobinson is fixed, popup windows are supported in phantomjs 1.7.

Now how about Casper? Is there a way to wait for a popup to be opened, then do some stuff on that page, and switch back?


@tlrobinson indeed, that would be plain handy. Though I don't have an API in mind, do you have any suggestion? eg:

casper.waitForPopup('<id?>', function(popup) {
    this.echo(popup.url + ' is loaded and is the current active page');

But I'm not convinced at all :/


Casper doesn't really support using two pages in a single flow, does it?

Not really atm, but that may be worked out, with a bit of refactoring though. The coupling between a casper instance and a page is nasty and was a bad design decision at the time the project was started, but I have hopes it can evolve to something more decoupled in the future — though we may wait for a 2.0 for that.

In the meanwhile, my current approach is to try to provide features without redoing everything from scratch nor breaking BC for existing users. I know it's a bit frustrating, but casperjs is just a pet project for me right now and I don't see much PRs nor design proposal coming, that's why I'm often asking for a bit of help :)


Fixed with the addition of waitForPopup() & withPopup()

@n1k0 n1k0 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.