0
0
Selenium Pythontesting~10 mins

Multi-select handling in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test selects multiple options from a multi-select dropdown and verifies that the correct options are selected.

Test Code - Selenium
Selenium Python
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import unittest

class TestMultiSelect(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/multiselect')

    def test_multi_select(self):
        select_element = self.driver.find_element('id', 'fruits')
        multi_select = Select(select_element)
        # Select multiple options by visible text
        multi_select.select_by_visible_text('Apple')
        multi_select.select_by_visible_text('Banana')
        multi_select.select_by_visible_text('Cherry')

        selected_options = [option.text for option in multi_select.all_selected_options]
        self.assertIn('Apple', selected_options)
        self.assertIn('Banana', selected_options)
        self.assertIn('Cherry', selected_options)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 10 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open, ready to navigate-PASS
2Browser navigates to 'https://example.com/multiselect'Page with multi-select dropdown loaded-PASS
3Find element with id 'fruits' representing the multi-select dropdownMulti-select dropdown element located-PASS
4Select 'Apple' option by visible text'Apple' option is selected in the dropdown-PASS
5Select 'Banana' option by visible text'Banana' option is selected along with 'Apple'-PASS
6Select 'Cherry' option by visible text'Cherry', 'Banana', and 'Apple' options are all selected-PASS
7Retrieve all selected options' textList of selected options: ['Apple', 'Banana', 'Cherry']Check that 'Apple' is in selected optionsPASS
8Assert 'Banana' is in selected optionsSelected options list unchangedCheck that 'Banana' is in selected optionsPASS
9Assert 'Cherry' is in selected optionsSelected options list unchangedCheck that 'Cherry' is in selected optionsPASS
10Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: If the multi-select dropdown element with id 'fruits' is not found or options are not selectable
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after selecting multiple options?
AThat the dropdown is disabled after selection
BThat only the last selected option is selected
CThat all selected options appear in the list of selected options
DThat the page URL changes after selection
Key Result
Always verify that the multi-select element exists before interacting and confirm all intended options are selected by checking the selected options list.