0
0
Selenium Pythontesting~20 mins

Multi-select handling in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-Select Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[]
B['Apple']
C['Banana']
D['Apple', 'Banana']
Attempts:
2 left
💡 Hint
Remember that Select allows multiple selections if the dropdown supports it.
assertion
intermediate
2: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]
Aassert 'Red' in selected_texts and 'Blue' in selected_texts and len(selected_texts) == 2
Bassert set(selected_texts) == {'Red', 'Blue'}
Cassert selected_texts == ['Red', 'Blue']
Dassert selected_texts[0] == 'Red' and selected_texts[1] == 'Blue'
Attempts:
2 left
💡 Hint
Order of selection may vary, so use a method that ignores order.
🔧 Debug
advanced
2: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()
ANoSuchElementException because 'Opel' is not in the dropdown
BNo error; all options are selected then deselected successfully
CInvalidElementStateException because 'deselect_all' is called on a non-multi-select dropdown
DAttributeError because 'deselect_all' method does not exist
Attempts:
2 left
💡 Hint
Check if the dropdown supports multiple selections before calling deselect_all.
locator
advanced
2: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?
Adriver.find_element('css selector', 'select[name="languages"]')
Bdriver.find_element('id', 'languages')
Cdriver.find_element('xpath', '//select[@name="languages"]')
Ddriver.find_element('class name', 'languages')
Attempts:
2 left
💡 Hint
Consider readability, stability, and specificity of locators.
framework
expert
3: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
A
from selenium.webdriver.support.ui import Select

def select_multiple_options(select_element, options_list):
    select = Select(select_element)
    for option in options_list:
        select.select_by_visible_text(option)
B
def select_multiple_options(select_element, options_list):
    select = Select(select_element)
    select.select_by_value(options_list)
C
from selenium.webdriver.support.ui import Select

def select_multiple_options(select_element, options_list):
    select = Select(select_element)
    select.select_by_visible_text(options_list)
D
def select_multiple_options(select_element, options_list):
    for option in options_list:
        select_element.select_by_visible_text(option)
Attempts:
2 left
💡 Hint
Remember to create a Select object and iterate over the list to select each option.