Challenge - 5 Problems
Date Picker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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}')
Attempts:
2 left
💡 Hint
Think about what happens if the date picker and calendar popup exist and are interactable.
✗ Incorrect
If the date picker input with ID 'datePicker' exists and clicking it shows a calendar popup with class 'calendar-popup', then the code finds the day '15' and clicks it successfully, printing 'Date selected successfully'. If any element is missing or not interactable, an exception would be caught and printed instead.
❓ locator
intermediate1: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?
Attempts:
2 left
💡 Hint
Use attributes that are stable and descriptive for accessibility.
✗ Incorrect
Using the aria-label attribute is best practice for accessibility and stability. The class name might be reused elsewhere, the text '>' is not reliable, and the ID does not exist.
❓ assertion
advanced1: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')
Attempts:
2 left
💡 Hint
Check exact value equality for input fields.
✗ Incorrect
The input's value attribute should exactly match '2024-06-15'. Option D uses assertEqual with the correct format. Option D uses wrong date format. Option D allows partial match which is less strict. Option D is logically correct but less clear.
🔧 Debug
advanced2: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')
Attempts:
2 left
💡 Hint
Consider how date pickers often restrict direct typing.
✗ Incorrect
Many date pickers have inputs that are read-only or disabled for typing. They require user interaction with the calendar widget. Trying to send keys causes ElementNotInteractableException.
❓ framework
expert2: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?
Attempts:
2 left
💡 Hint
Use waits that wait for specific conditions rather than fixed delays.
✗ Incorrect
Explicit waits with expected conditions allow waiting for specific elements or states, making tests reliable and efficient. Implicit waits apply globally and may cause unpredictable delays. Thread.sleep() is inefficient and brittle. Try-except retry is manual and error-prone.