0
0
Selenium Pythontesting~10 mins

Date picker interaction in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page with a date picker, selects a specific date, and verifies the date is correctly set in the input field.

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 DatePickerTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/datepicker')

    def test_select_date(self):
        driver = self.driver
        wait = WebDriverWait(driver, 10)

        # Wait for date picker input to be clickable
        date_input = wait.until(EC.element_to_be_clickable((By.ID, 'date-input')))
        date_input.click()

        # Wait for the date picker widget to appear
        date_picker = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'ui-datepicker-calendar')))

        # Select the date 15 from the calendar
        date_cell = date_picker.find_element(By.XPATH, ".//a[text()='15']")
        date_cell.click()

        # Verify the input value is set to the expected date string
        expected_date = '06/15/2024'
        actual_date = date_input.get_attribute('value')
        self.assertEqual(actual_date, expected_date, f"Date input value should be {expected_date}")

    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, navigated to 'https://example.com/datepicker' page-PASS
2Waits until date picker input with ID 'date-input' is clickableDate input field is visible and ready for interaction-PASS
3Clicks on the date picker input field to open the calendar widgetDate picker calendar widget appears on the page-PASS
4Waits until the calendar widget with class 'ui-datepicker-calendar' is visibleCalendar widget is fully loaded and visible-PASS
5Finds the date cell with text '15' inside the calendar and clicks itDate '15' is selected in the calendar-PASS
6Reads the value attribute of the date input fieldDate input field shows the selected date stringCheck if input value equals '06/15/2024'PASS
7Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: Date cell with text '15' is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test do after clicking the date input field?
ACloses the browser
BImmediately reads the input value
CWaits for the calendar widget to appear
DClicks the submit button
Key Result
Always wait explicitly for elements to be ready before interacting, especially with dynamic widgets like date pickers, to avoid flaky tests.