1515# specific language governing permissions and limitations
1616# under the License.
1717
18+ from typing import List
19+
1820from selenium .common .exceptions import NoSuchElementException
1921from selenium .common .exceptions import UnexpectedTagNameException
2022from selenium .webdriver .common .by import By
23+ from selenium .webdriver .remote .webelement import WebElement
2124
2225
2326class Select :
24- def __init__ (self , webelement ) -> None :
27+ def __init__ (self , webelement : WebElement ) -> None :
2528 """Constructor. A check is made that the given element is, indeed, a
2629 SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
2730
@@ -39,26 +42,26 @@ def __init__(self, webelement) -> None:
3942 self .is_multiple = multi and multi != "false"
4043
4144 @property
42- def options (self ):
45+ def options (self ) -> List [ WebElement ] :
4346 """Returns a list of all options belonging to this select tag."""
4447 return self ._el .find_elements (By .TAG_NAME , "option" )
4548
4649 @property
47- def all_selected_options (self ):
50+ def all_selected_options (self ) -> List [ WebElement ] :
4851 """Returns a list of all selected options belonging to this select
4952 tag."""
5053 return [opt for opt in self .options if opt .is_selected ()]
5154
5255 @property
53- def first_selected_option (self ):
56+ def first_selected_option (self ) -> WebElement :
5457 """The first selected option in this select tag (or the currently
5558 selected option in a normal select)"""
5659 for opt in self .options :
5760 if opt .is_selected ():
5861 return opt
5962 raise NoSuchElementException ("No options are selected" )
6063
61- def select_by_value (self , value ) :
64+ def select_by_value (self , value : str ) -> None :
6265 """Select all options that have a value matching the argument. That is,
6366 when given "foo" this would select an option like:
6467
@@ -80,7 +83,7 @@ def select_by_value(self, value):
8083 if not matched :
8184 raise NoSuchElementException (f"Cannot locate option with value: { value } " )
8285
83- def select_by_index (self , index ) :
86+ def select_by_index (self , index : int ) -> None :
8487 """Select the option at the given index. This is done by examining the
8588 "index" attribute of an element, and not merely by counting.
8689
@@ -96,7 +99,7 @@ def select_by_index(self, index):
9699 return
97100 raise NoSuchElementException (f"Could not locate element with index { index } " )
98101
99- def select_by_visible_text (self , text ) :
102+ def select_by_visible_text (self , text : str ) -> None :
100103 """Select all options that display text matching the argument. That is,
101104 when given "Bar" this would select an option like:
102105
@@ -145,7 +148,7 @@ def deselect_all(self) -> None:
145148 for opt in self .options :
146149 self ._unset_selected (opt )
147150
148- def deselect_by_value (self , value ) :
151+ def deselect_by_value (self , value : str ) -> None :
149152 """Deselect all options that have a value matching the argument. That
150153 is, when given "foo" this would deselect an option like:
151154
@@ -167,7 +170,7 @@ def deselect_by_value(self, value):
167170 if not matched :
168171 raise NoSuchElementException (f"Could not locate element with value: { value } " )
169172
170- def deselect_by_index (self , index ) :
173+ def deselect_by_index (self , index : int ) -> None :
171174 """Deselect the option at the given index. This is done by examining
172175 the "index" attribute of an element, and not merely by counting.
173176
@@ -184,7 +187,7 @@ def deselect_by_index(self, index):
184187 return
185188 raise NoSuchElementException (f"Could not locate element with index { index } " )
186189
187- def deselect_by_visible_text (self , text ) :
190+ def deselect_by_visible_text (self , text : str ) -> None :
188191 """Deselect all options that display text matching the argument. That
189192 is, when given "Bar" this would deselect an option like:
190193
0 commit comments