Test Overview
This test demonstrates how implicit waits help Selenium wait for elements to appear before interacting with them. It verifies that a button can be clicked after a delay.
This test demonstrates how implicit waits help Selenium wait for elements to appear before interacting with them. It verifies that a button can be clicked after a delay.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException import time def test_implicit_wait(): driver = webdriver.Chrome() driver.implicitly_wait(5) # Wait up to 5 seconds for elements driver.get('https://example.com/delayed_button') try: button = driver.find_element(By.ID, 'delayed-btn') button.click() assert True except NoSuchElementException: assert False, 'Button not found' finally: driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to navigate | - | PASS |
| 2 | Set implicit wait to 5 seconds | Driver will wait up to 5 seconds when searching for elements | - | PASS |
| 3 | Navigate to 'https://example.com/delayed_button' | Page loads with a button that appears after a short delay | - | PASS |
| 4 | Find element with ID 'delayed-btn' | Driver waits up to 5 seconds for the button to appear | Element 'delayed-btn' is found within wait time | PASS |
| 5 | Click the button | Button is clicked successfully | Click action performed without error | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |