Test Overview
This test opens a web page, finds an input element by its name attribute, enters text, and verifies the input value.
This test opens a web page, finds an input element by its name attribute, enters text, and verifies the input 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 TestFindElementByName(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_find_element_by_name(self): driver = self.driver # Wait until the input element with name 'username' is present username_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.NAME, 'username')) ) username_input.clear() username_input.send_keys('testuser') # Verify the input value self.assertEqual(username_input.get_attribute('value'), 'testuser') 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, ready to load URL | - | PASS |
| 2 | Navigates to 'https://example.com/login' | Login page is loaded with input fields | - | PASS |
| 3 | Waits until element with name 'username' is present | Input field with name 'username' is visible on page | Element located by name 'username' is found | PASS |
| 4 | Clears the input field and types 'testuser' | Input field now contains text 'testuser' | - | PASS |
| 5 | Checks that input field value equals 'testuser' | Input field value is 'testuser' | Assert input value == 'testuser' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |