Challenge - 5 Problems
Multi-Select Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of selecting multiple options in a multi-select dropdown
What will be the output of the following Selenium Python code snippet when selecting multiple options from a multi-select dropdown?
Selenium Python
from selenium.webdriver.support.ui import Select # Assume driver is a valid WebDriver instance select_element = driver.find_element('id', 'fruits') select = Select(select_element) select.select_by_visible_text('Apple') select.select_by_value('banana') selected_options = [option.text for option in select.all_selected_options] print(selected_options)
Attempts:
2 left
💡 Hint
Remember that Select allows multiple selections if the dropdown supports it.
✗ Incorrect
The code selects two options by visible text and by value. Since the dropdown supports multiple selections, both options remain selected and are returned in the list.
❓ assertion
intermediate2:00remaining
Correct assertion to verify multiple selected options
Which assertion correctly verifies that the multi-select dropdown has exactly 'Red' and 'Blue' selected, regardless of order?
Selenium Python
from selenium.webdriver.support.ui import Select select_element = driver.find_element('id', 'colors') select = Select(select_element) selected_texts = [opt.text for opt in select.all_selected_options]
Attempts:
2 left
💡 Hint
Order of selection may vary, so use a method that ignores order.
✗ Incorrect
Using set comparison ensures the selected options are exactly 'Red' and 'Blue' regardless of order. Option B and D fail if order changes. Option B is correct logically but less concise than A.
🔧 Debug
advanced2:00remaining
Identify the error in multi-select option selection code
What error will occur when running this Selenium Python code to select multiple options?
Selenium Python
select_element = driver.find_element('id', 'cars') select = Select(select_element) select.select_by_visible_text('Volvo') select.select_by_visible_text('Saab') select.select_by_visible_text('Opel') select.deselect_all()
Attempts:
2 left
💡 Hint
Check if the dropdown supports multiple selections before calling deselect_all.
✗ Incorrect
If the dropdown is not multi-select, calling deselect_all() raises InvalidElementStateException. The code assumes multi-select but may fail if the dropdown is single-select.
❓ locator
advanced2:00remaining
Best locator strategy for multi-select dropdown
Which locator strategy is best to find a multi-select dropdown with name attribute 'languages' for stable and readable Selenium tests?
Attempts:
2 left
💡 Hint
Consider readability, stability, and specificity of locators.
✗ Incorrect
Using CSS selector with attribute name is concise, readable, and stable if the name attribute is unique. XPath works but is more verbose. ID may not exist. Class name may select multiple elements.
❓ framework
expert3:00remaining
Designing a reusable function to select multiple options by visible text
Which Python function correctly selects multiple options by visible text from a multi-select dropdown element using Selenium?
Selenium Python
def select_multiple_options(select_element, options_list): # Fill in the function body
Attempts:
2 left
💡 Hint
Remember to create a Select object and iterate over the list to select each option.
✗ Incorrect
Option A correctly creates a Select object and loops through each visible text to select options. Option A fails because select_element is a WebElement, not Select. Option A passes a list to select_by_visible_text which expects a string. Option A uses select_by_value incorrectly with a list.