Test Overview
This test opens a web page and finds a link using its visible text. It then clicks the link and verifies the new page title to confirm navigation.
This test opens a web page and finds a link using its visible text. It then clicks the link and verifies the new page title to confirm navigation.
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 TestFindByLinkText(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com') def test_click_link_by_text(self): driver = self.driver # Wait until the link with text 'More information...' is present link = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.LINK_TEXT, 'More information...')) ) link.click() # Wait for the new page title to contain 'IANA' WebDriverWait(driver, 10).until(EC.title_contains('IANA')) self.assertIn('IANA', driver.title) 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 opens at https://example.com homepage | - | PASS |
| 2 | Wait until link with text 'More information...' is present | Page loaded with visible link text 'More information...' | Check presence of link element by link text | PASS |
| 3 | Click the link found by link text | Browser navigates to linked page | - | PASS |
| 4 | Wait until page title contains 'IANA' | New page loaded with title containing 'IANA' | Verify page title contains 'IANA' | PASS |
| 5 | Assert that 'IANA' is in the page title | Page title is 'IANA — IANA-managed Reserved Domains' or similar | assertIn('IANA', driver.title) | PASS |
| 6 | Test ends and browser closes | Browser window closed | - | PASS |