user3416803
user3416803

Reputation: 379

How to open link in childframe using PhantomJS?

I have a site with 3 frames. I want to visit main page, and then switch to child frame and open another page in this frame. Is this possible? There is not really much about this in the documentation.

Upvotes: 2

Views: 50

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

You can switch to the parent/main frame of the frame that you want to change the URL for and simply change the src attribute:

page.evaluate(function(pos, newSrc){
    document.querySelectorAll("iframe")[pos].src = newSrc;
}, 0, "http://example.com");

// wait a little
setTimeout(function(){
    page.switchToChildFrame(0);
    // do something
}, 2000);

Upvotes: 2

Related Questions