CasperJS Closing iframes / Scripting parent from iframe

367 Views Asked by At

I have an iframe on my page that pops up to allow the user to insert some data into the parent page. When the user clicks the "Add" button in the frame, it calls a parent function to close the frame and insert the data.

Casper is able to find the "Add" button in the frame, but when I click it, nothing happens. Fairly sure I'm doing this right. Possible bug/not supported by Phantom maybe?

Code:

casper.withFrame(0,function() {
  this.waitForSelector('.button[name="add button"]');
});

casper.withFrame(0,function() {
  this.click('.button[name="add button"]');
});

casper.wait(1000);

casper.then(function() {
  this.capture('capture.png');
});

capture.png shows the frame still open, but if I perform the actions myself in Chrome, the frame closes correctly.

1

There are 1 best solutions below

0
On

Why don't you add this.click('.button[name="add button"]');in the callback of this.waitForSelector('.button[name="add button"]');?

This way you will be sure that click was called after button was found.