Test Overview
This test opens a web page, finds a text input box, types the text "Hello World" into it, and verifies that the input box contains the typed text.
This test opens a web page, finds a text input box, types the text "Hello World" into it, and verifies that the input box contains the typed text.
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 TestTypingText(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/input') def test_typing_text(self): driver = self.driver wait = WebDriverWait(driver, 10) input_box = wait.until(EC.presence_of_element_located((By.ID, 'text-input'))) input_box.clear() input_box.send_keys('Hello World') self.assertEqual(input_box.get_attribute('value'), 'Hello World') 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 the page | — | PASS |
| 2 | Navigates to URL 'https://example.com/input' | Page with input box loaded and visible | — | PASS |
| 3 | Waits until element with ID 'text-input' is present | Input box is found on the page | Element with ID 'text-input' is present | PASS |
| 4 | Clears any existing text in the input box | Input box is empty | — | PASS |
| 5 | Types text 'Hello World' into the input box using send_keys | Input box shows text 'Hello World' | — | PASS |
| 6 | Checks that the input box value is exactly 'Hello World' | Input box value attribute equals 'Hello World' | Assert input_box.get_attribute('value') == 'Hello World' | PASS |
| 7 | Test ends and browser closes | Browser window closed | — | PASS |
send_keys method do in Selenium Python?send_keyssend_keys method simulates typing text into input fields or editable elements in Selenium.click(), text property, or WebDriverWait.input_box?send_keys().send_keys on the element with the text as a string argument.input_box = driver.find_element(By.ID, "username")
input_box.send_keys("user123")
print(input_box.get_attribute("value"))send_keys("user123") types "user123" into the input box, setting its value attribute.get_attribute("value") returns the current text inside the input box, which is "user123".input_box = driver.find_element(By.ID, "user") input_box.send_keys(admin)
admin is not in quotes, so Python treats it as a variable, causing a NameError.send_keys("admin").clear() method to remove any existing text in the input box.send_keys("mypassword") to type the password.Pass the test and this pattern moves unknown