Test Overview
This test opens a web page, finds an element using its class name, and verifies that the element's text matches the expected value.
This test opens a web page, finds an element using its class name, and verifies that the element's text matches the expected value.
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 TestFindByClassName(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com') def test_find_element_by_class_name(self): driver = self.driver wait = WebDriverWait(driver, 10) element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'example'))) self.assertEqual(element.text, 'Example Domain') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open, ready to load the page | - | PASS |
| 2 | Browser navigates to 'https://example.com' | Page 'https://example.com' is loaded and visible | - | PASS |
| 3 | Waits up to 10 seconds for element with class name 'example' to be present | Element with class 'example' is found on the page | Element presence verified | PASS |
| 4 | Checks that the element's text equals 'Example Domain' | Element text is 'Example Domain' | Assert element.text == 'Example Domain' | PASS |
| 5 | Browser closes and test ends | Browser window closed | - | PASS |