|
| 1 | +from seleniumbase import BaseCase |
| 2 | + |
| 3 | + |
| 4 | +class SelectTestClass(BaseCase): |
| 5 | + def test_base(self): |
| 6 | + self.open("https://seleniumbase.io/demo_page") |
| 7 | + |
| 8 | + expected_option_texts = [ |
| 9 | + "Set to 25%", "Set to 50%", "Set to 75%", "Set to 100%" |
| 10 | + ] |
| 11 | + option_texts = self.get_select_options("select#mySelect") |
| 12 | + self.assert_equal(option_texts, expected_option_texts) |
| 13 | + |
| 14 | + expected_option_indexes = ["0", "1", "2", "3"] |
| 15 | + option_indexes = self.get_select_options( |
| 16 | + "select#mySelect", attribute="index" |
| 17 | + ) |
| 18 | + self.assert_equal(option_indexes, expected_option_indexes) |
| 19 | + |
| 20 | + expected_option_values = ["25%", "50%", "75%", "100%"] |
| 21 | + option_values = self.get_select_options( |
| 22 | + "select#mySelect", attribute="value" |
| 23 | + ) |
| 24 | + self.assert_equal(option_values, expected_option_values) |
| 25 | + |
| 26 | + for index, option_text in enumerate(option_texts): |
| 27 | + self.select_option_by_text("#mySelect", option_text) |
| 28 | + selected_value = self.get_attribute("#mySelect", "value") |
| 29 | + self.assert_equal(selected_value, option_values[index]) |
| 30 | + |
| 31 | + for index, option_value in enumerate(option_values): |
| 32 | + self.select_option_by_value("#mySelect", option_value) |
| 33 | + selected_value = self.get_attribute("#mySelect", "value") |
| 34 | + self.assert_equal(selected_value, option_values[index]) |
| 35 | + |
| 36 | + for index, option_index in enumerate(option_indexes): |
| 37 | + self.select_option_by_index("#mySelect", option_index) |
| 38 | + # assert_attribute() combines get_attribute() and assert_equal() |
| 39 | + # It also highlights the element when Demo Mode is enabled. |
| 40 | + self.assert_attribute("#mySelect", "value", option_values[index]) |
0 commit comments