Challenge - 5 Problems
Dropdown Mastery Badge
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 Python code snippet?
Consider the following Selenium Python code that selects an option from a dropdown menu. What will be printed after execution?
Selenium Python
from selenium.webdriver.support.ui import Select class MockElement: def __init__(self): self.selected_option = None def find_element(self, by, value): return self def click(self): pass def get_attribute(self, attr): if attr == 'value': return self.selected_option select_element = MockElement() select = Select(select_element) # Simulate selecting by visible text select.select_by_visible_text = lambda text: setattr(select_element, 'selected_option', text) select.select_by_visible_text('Option 2') print(select_element.selected_option)
Attempts:
2 left
💡 Hint
Focus on what the lambda function does when called.
✗ Incorrect
The lambda function replaces the select_by_visible_text method to set the selected_option attribute to the given text. So after calling select_by_visible_text('Option 2'), selected_option is 'Option 2'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the selected option text in a dropdown?
You have a Selenium Select object named 'select'. Which assertion correctly checks that the currently selected option's visible text is 'Apple'?
Attempts:
2 left
💡 Hint
Check the Selenium Select API for the property that returns the selected option element.
✗ Incorrect
The 'first_selected_option' property returns the WebElement of the selected option. Accessing its 'text' gives the visible text. The other options are invalid or do not exist.
❓ locator
advanced2:00remaining
Which locator strategy is best for finding a dropdown by its label text?
You want to locate a dropdown menu associated with the label text 'Country'. Which locator strategy is the most reliable and accessible?
Attempts:
2 left
💡 Hint
Think about how labels and inputs are connected for accessibility.
✗ Incorrect
Option C uses the label text to find the select element next to it, which is reliable if the label is properly associated. Other options rely on id or name which may not always be present or unique.
🔧 Debug
advanced2:30remaining
Why does this Selenium code fail to select an option?
Given this code snippet, why does the dropdown selection fail?
Selenium Python
from selenium.webdriver.support.ui import Select select_element = driver.find_element('id', 'fruits') select = Select(select_element) select.select_by_value('banana') # The dropdown does not change selection after this code runs.
Attempts:
2 left
💡 Hint
Check the HTML tag of the element found by id 'fruits'.
✗ Incorrect
The Select class only works with
❓ framework
expert3:00remaining
How to implement a reusable dropdown selection helper in Selenium Python?
You want to create a helper function that selects an option from any dropdown by visible text and waits until the selection is confirmed. Which implementation is correct?
Attempts:
2 left
💡 Hint
Consider waiting for the element and verifying the selection after action.
✗ Incorrect
Option B waits for the dropdown element to be present, selects by visible text, then waits until the selection is confirmed. This makes the helper reliable and reusable. Other options lack waiting or use incorrect methods.