0
0
Selenium Pythontesting~10 mins

Typing text (send_keys) in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Selenium
Selenium Python
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()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open, ready to load the page-PASS
2Navigates to URL 'https://example.com/input'Page with input box loaded and visible-PASS
3Waits until element with ID 'text-input' is presentInput box is found on the pageElement with ID 'text-input' is presentPASS
4Clears any existing text in the input boxInput box is empty-PASS
5Types text 'Hello World' into the input box using send_keysInput box shows text 'Hello World'-PASS
6Checks 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
7Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: The input box with ID 'text-input' is not found on the page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test do after opening the browser and loading the page?
AIt waits for the input box with ID 'text-input' to appear
BIt immediately types text without waiting
CIt closes the browser
DIt refreshes the page
Key Result
Always wait explicitly for elements to be present before interacting with them to avoid timing issues in tests.