Manipulating frames with webpage

A web page may have different frames, and even some frames inside frames. If you want to do things related to a specific frame, like evaluating code, the webpage object have some methods to select the frame you want to work with.

These methods are:

Exemple to select an frame

root window:
<frameset>
  <frame name="f1" src="frame1.html" />
  <frame name="f2" src="frame2.html" />
</frameset>
frame1.html:
<html>... <iframe name="f3" src="frame3.html">... </html>
frame2.html and frame3.html:
<html>... simple web page ....</html>

To select frame2.html, you’ll do:

webpage.switchToFrame('f2');

If you want to select the frame3.html after that, you’ll do:

// first return to the parent frame
webpage.switchToParentFrame(); // or switchToMainFrame() in this example

// then select frame1.html because frame3.html is a child of it
webpage.switchToFrame('f1');

// then select frame3.html
webpage.switchToFrame('f3');

Manipulating the current frame

After selecting a frame, you have some properties to retrieve the frame properties: webpage.frameContent, webpage.frameTitle, webpage.frameName, webpage.frameUrl, webpage.framePlainText.

And you can evaluate javascript in the current frame with evaluateJavaScript(), evaluate(), evaluateAsync(), includeJs() or injectJs()

Table Of Contents

Previous topic

Dealing with HTTP authentication

Next topic

Creating addons for SlimerJS

This Page