Test Overview
This test opens a web page, finds an element using its ID, clicks it, and verifies the expected page change.
This test opens a web page, finds an element using its ID, clicks it, and verifies the expected page change.
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 TestFindElementByID(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com') def test_click_button_by_id(self): driver = self.driver # Wait until the button with ID 'submit-btn' is present button = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'submit-btn')) ) button.click() # Verify the URL changed to expected page WebDriverWait(driver, 10).until( EC.url_contains('submit-success') ) self.assertIn('submit-success', driver.current_url) 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 window is open at 'https://example.com' | - | PASS |
| 2 | Wait until element with ID 'submit-btn' is present | Page loaded with a button having ID 'submit-btn' | Element with ID 'submit-btn' is found | PASS |
| 3 | Click the button with ID 'submit-btn' | Button clicked, page starts navigation | - | PASS |
| 4 | Wait until URL contains 'submit-success' | Browser URL changes to include 'submit-success' | Current URL contains 'submit-success' | PASS |
| 5 | Test ends and browser closes | Browser window closed | - | PASS |