Test Overview
This test opens a webpage with a dropdown menu, selects an option by visible text using Selenium's Select class, and verifies the correct option is selected.
This test opens a webpage with a dropdown menu, selects an option by visible text using Selenium's Select class, and verifies the correct option is selected.
from selenium import webdriver from selenium.webdriver.support.ui import Select from selenium.webdriver.common.by import By import unittest class TestDropdownSelection(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/dropdown') def test_select_option_by_visible_text(self): driver = self.driver dropdown_element = driver.find_element(By.ID, 'dropdown') select = Select(dropdown_element) select.select_by_visible_text('Option 2') selected_option = select.first_selected_option self.assertEqual(selected_option.text, 'Option 2') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to navigate | - | PASS |
| 2 | Browser navigates to 'https://example.com/dropdown' | Page with dropdown menu loaded | - | PASS |
| 3 | Find dropdown element by ID 'dropdown' | Dropdown element located on the page | - | PASS |
| 4 | Create Select object for dropdown element | Select object ready to interact with dropdown | - | PASS |
| 5 | Select option with visible text 'Option 2' | Dropdown option 'Option 2' is selected | Verify selected option text is 'Option 2' | PASS |
| 6 | Test ends and browser closes | Browser window closed | - | PASS |