Test Overview
This test opens a web page, finds a heading element, retrieves its text, and verifies that the text matches the expected value.
This test opens a web page, finds a heading element, retrieves its text, and verifies that the text matches the expected value.
from selenium import webdriver from selenium.webdriver.common.by import By import unittest class TestGetElementText(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com') def test_heading_text(self): heading = self.driver.find_element(By.TAG_NAME, 'h1') text = heading.text self.assertEqual(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 | Browser window is open and ready | - | PASS |
| 2 | Navigates to 'https://example.com' | Page loads with heading 'Example Domain' | - | PASS |
| 3 | Finds element with tag name 'h1' | Element <h1> with text 'Example Domain' is located | - | PASS |
| 4 | Retrieves text from the heading element | Text value is 'Example Domain' | - | PASS |
| 5 | Checks if the text equals 'Example Domain' | Text matches expected string | assertEqual(text, 'Example Domain') | PASS |
| 6 | Closes the browser | Browser window is closed | - | PASS |