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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser opened at URL https://example.com/nested_iframes showing main page with nested iFrames | - | PASS |
| 2 | Waits for outer iframe with id 'outer-frame' and switches to it | Browser context switched inside outer iframe | Frame 'outer-frame' is available and switched | PASS |
| 3 | Waits for inner iframe with name 'inner-frame' and switches to it | Browser context switched inside inner iframe nested within outer iframe | Frame 'inner-frame' is available and switched | PASS |
| 4 | Finds button with CSS selector 'button#click-me' inside inner iframe | Button element is visible and clickable inside inner iframe | Button element found and clickable | PASS |
| 5 | Clicks the button | Button clicked, page updates button text | - | PASS |
| 6 | Checks that button text changed to 'Clicked!' | Button text is now 'Clicked!' | Assert button.text == 'Clicked!' | PASS |
| 7 | Test ends and browser closes | Browser closed | - | PASS |