This script opens a sample date picker, selects the 15th day, and checks if the input shows the correct date.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time
# Setup Chrome options
options = Options()
options.add_argument('--headless') # Run without opening a window
# Setup Chrome driver
service = Service()
browser = webdriver.Chrome(service=service, options=options)
try:
# Open sample page with date picker
browser.get('https://jqueryui.com/datepicker/')
# Switch to frame containing the date picker
browser.switch_to.frame(browser.find_element(By.CLASS_NAME, 'demo-frame'))
# Find the date input and click to open date picker
date_input = browser.find_element(By.ID, 'datepicker')
date_input.click()
time.sleep(1) # Wait for date picker to appear
# Select the 15th day
day_15 = browser.find_element(By.XPATH, "//a[text()='15']")
day_15.click()
# Verify the input value changed to the selected date
selected_date = date_input.get_attribute('value')
print(f'Selected date: {selected_date}')
# Simple assertion
assert '15' in selected_date, 'Date picker did not select the 15th day.'
finally:
browser.quit()