0
0
Selenium Pythontesting~20 mins

Date picker interaction in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Date Picker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium code snippet?
Consider the following Selenium Python code that tries to select a date from a date picker widget. What will be the printed output after execution?
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

# Assume driver is already initialized and navigated to the page
try:
    date_input = driver.find_element(By.ID, 'datePicker')
    date_input.click()
    # Wait for the calendar popup
    calendar = WebDriverWait(driver, 5).until(
        EC.visibility_of_element_located((By.CLASS_NAME, 'calendar-popup'))
    )
    # Select the 15th day
    day_15 = calendar.find_element(By.XPATH, ".//td[text()='15']")
    day_15.click()
    print('Date selected successfully')
except Exception as e:
    print(f'Error: {e}')
ADate selected successfully
BError: no such element: Unable to locate element: {"method":"id","selector":"datePicker"}
CError: TimeoutException
DError: ElementNotInteractableException
Attempts:
2 left
💡 Hint
Think about what happens if the date picker and calendar popup exist and are interactable.
locator
intermediate
1:30remaining
Which locator is best to select the 'Next Month' button in a date picker?
You want to automate clicking the 'Next Month' button in a date picker widget. The button has the HTML: . Which locator is the best practice to use in Selenium?
ABy.CLASS_NAME, 'nav-next'
BBy.CSS_SELECTOR, "button[aria-label='Next Month']"
CBy.XPATH, "//button[text()='>']"
DBy.ID, 'next-month-btn'
Attempts:
2 left
💡 Hint
Use attributes that are stable and descriptive for accessibility.
assertion
advanced
1:30remaining
Which assertion correctly verifies the selected date in a date picker input?
After selecting a date, the input field with ID 'datePicker' should show '2024-06-15'. Which assertion in Python unittest is correct?
Selenium Python
selected_date = driver.find_element(By.ID, 'datePicker').get_attribute('value')
Aself.assertFalse(selected_date != '2024-06-15')
Bself.assertTrue(selected_date == '15-06-2024')
Cself.assertIn('2024-06-15', selected_date)
Dself.assertEqual(selected_date, '2024-06-15')
Attempts:
2 left
💡 Hint
Check exact value equality for input fields.
🔧 Debug
advanced
2:00remaining
Why does this Selenium code fail to select a date?
Given this code snippet, why does it raise ElementNotInteractableException? code: date_input = driver.find_element(By.ID, 'datePicker') date_input.send_keys('2024-06-15')
AThe date picker input is read-only and requires clicking the calendar to select a date.
BThe locator By.ID, 'datePicker' is incorrect and finds no element.
Csend_keys is not supported on input elements.
DThe date format '2024-06-15' is invalid for the input.
Attempts:
2 left
💡 Hint
Consider how date pickers often restrict direct typing.
framework
expert
2:30remaining
Which test framework feature best supports waiting for dynamic date picker elements?
You are automating tests for a web app with a dynamic date picker that loads calendar days asynchronously. Which Selenium WebDriver feature best handles waiting for the calendar days to appear before selecting a date?
AImplicit Wait set globally on the WebDriver instance
BThread.sleep() to pause fixed time before interacting
CExplicit Wait with Expected Conditions targeting visibility of calendar day elements
DUsing try-except blocks to catch NoSuchElementException and retry
Attempts:
2 left
💡 Hint
Use waits that wait for specific conditions rather than fixed delays.