Skip to content
CodeKruPro

Read text from nested frames

Automation taskMedium-HardAsked in: Accenture, Capgemini, Cognizant, Infosys, TCS, Wipro

Interviewers ask: "How do you reach a frame inside another frame, and go back one level?" Switch one level at a time, outer frame first. Go up one level with the parent frame call.

Handle Nested Frames

Handle Nested Frames

Frames can be nested inside other frames. To reach a child frame, you must first switch to the parent frame, then to the child.

On the Frames page, the nested frame (name="nestedFrame") contains a child iframe with <h3>Child frame</h3>.

Nested Frame DOM Structure:

<!-- Main page -->
<iframe name="nestedFrame">        <!-- Step 1: switch here first -->
  <h2>Parent frame</h2>
  <iframe>                          <!-- Step 2: then switch here (index 0) -->
    <h3>Child frame</h3>
  </iframe>
</iframe>

You must switch to each frame level sequentially — you cannot skip directly to the child.

Task:

  1. Navigate to https://testkru.com/Interactions/Frames
  2. Switch to the parent frame (nestedFrame)
  3. Print the h2 text (parent frame content)
  4. Switch to the child frame inside it (index 0)
  5. Print the h3 text (child frame content)

Expected output:

Parent: Parent frame
Child: Child frame