Test Overview
This test opens a web page and finds a link using part of its text. It then clicks the link and checks if the new page title is correct.
This test opens a web page and finds a link using part of its text. It then clicks the link and checks if the new page title is correct.
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 TestPartialLinkText(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com') def test_click_partial_link_text(self): driver = self.driver wait = WebDriverWait(driver, 10) # Wait until the link with partial text is present link = wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'More information'))) link.click() # Wait for the new page title to be as expected wait.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 is open at 'https://example.com' homepage | - | PASS |
| 2 | Wait until link containing partial text 'More information' is present | Page loaded with visible link text 'More information...' | Check presence of element with partial link text 'More information' | PASS |
| 3 | Click the found link | Browser navigates to the linked page | - | PASS |
| 4 | Wait until page title contains 'IANA' | New page loaded with title containing 'IANA' | Verify page title includes '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 |