0
0
Selenium Pythontesting~10 mins

Date picker interaction in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find the date picker element by its ID.

Selenium Python
date_picker = driver.find_element(By.[1]("datePicker"))
Drag options to blanks, or click blank then click option'
ANAME
BCLASS_NAME
CTAG_NAME
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using CLASS_NAME or NAME instead of ID may not find the correct element.
Forgetting to import By from selenium.webdriver.common.by.
2fill in blank
medium

Complete the code to click the date picker element to open the calendar.

Selenium Python
date_picker = driver.find_element(By.ID, "datePicker")
date_picker.[1]()
Drag options to blanks, or click blank then click option'
Asend_keys
Bclick
Csubmit
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using send_keys instead of click to open the calendar.
Calling submit on a non-form element.
3fill in blank
hard

Fix the error in the code to select a date by visible text from the dropdown.

Selenium Python
from selenium.webdriver.support.ui import Select

month_dropdown = Select(driver.find_element(By.ID, "month"))
month_dropdown.select_by_[1]("March")
Drag options to blanks, or click blank then click option'
Avisible_text
Btext
Cindex
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using select_by_value when the visible text is needed.
Using select_by_text which is not a valid method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each day element's text to its WebElement if the day is greater than 15.

Selenium Python
days = driver.find_elements(By.CLASS_NAME, "day")
day_dict = {day.text: day for day in days if int(day.[1]) [2] 15}
Drag options to blanks, or click blank then click option'
Atext
Bget_attribute
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_attribute without specifying an attribute.
Using less than operator instead of greater than.
5fill in blank
hard

Fill all three blanks to create a test that asserts the selected date text matches the expected date.

Selenium Python
selected_date = driver.find_element(By.ID, [1]).text
expected_date = "2024-06-15"
assert selected_date [2] expected_date, "Date does not match"
print("Selected date is", [3])
Drag options to blanks, or click blank then click option'
A"selectedDate"
B==
Cselected_date
D"datePicker"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong element ID.
Using = instead of == in the assertion.
Printing the string literal instead of the variable.