0
0
Selenium Pythontesting~10 mins

Nested iFrames in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage with nested iFrames. It switches into the outer iFrame, then into the inner iFrame, finds a button inside, clicks it, and verifies the button's text changes as expected.

Test Code - Selenium
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest

class TestNestedIFrames(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/nested_iframes')
        self.wait = WebDriverWait(self.driver, 10)

    def test_click_button_in_nested_iframe(self):
        driver = self.driver
        wait = self.wait

        # Switch to outer iframe by id
        wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'outer-frame')))

        # Switch to inner iframe by name
        wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME, 'inner-frame')))

        # Find the button inside inner iframe
        button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button#click-me')))

        # Click the button
        button.click()

        # Verify button text changed
        self.assertEqual(button.text, 'Clicked!')

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser opened at URL https://example.com/nested_iframes showing main page with nested iFrames-PASS
2Waits for outer iframe with id 'outer-frame' and switches to itBrowser context switched inside outer iframeFrame 'outer-frame' is available and switchedPASS
3Waits for inner iframe with name 'inner-frame' and switches to itBrowser context switched inside inner iframe nested within outer iframeFrame 'inner-frame' is available and switchedPASS
4Finds button with CSS selector 'button#click-me' inside inner iframeButton element is visible and clickable inside inner iframeButton element found and clickablePASS
5Clicks the buttonButton clicked, page updates button text-PASS
6Checks that button text changed to 'Clicked!'Button text is now 'Clicked!'Assert button.text == 'Clicked!'PASS
7Test ends and browser closesBrowser closed-PASS
Failure Scenario
Failing Condition: The inner iframe is not found or the button inside it is missing or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
Which step shows switching into the inner iframe?
AStep 3
BStep 2
CStep 4
DStep 5
Key Result
Always switch to each iframe step-by-step when dealing with nested iFrames before interacting with elements inside them. Use explicit waits to ensure frames and elements are ready.