@@ -823,6 +823,37 @@ def select_option_by_text(self, dropdown_selector, option):
823823 % (dropdown_selector , option )
824824 )
825825
826+ def select_option_by_index (self , dropdown_selector , option ):
827+ element = self .find_element (dropdown_selector )
828+ element .scroll_into_view ()
829+ options = element .query_selector_all ("option" )
830+ count = 0
831+ for found_option in options :
832+ if count == int (option ):
833+ found_option .select_option ()
834+ return
835+ count += 1
836+ raise Exception (
837+ "Unable to find index option {%s} in dropdown {%s}!"
838+ % (dropdown_selector , option )
839+ )
840+
841+ def select_option_by_value (self , dropdown_selector , option ):
842+ element = self .find_element (dropdown_selector )
843+ element .scroll_into_view ()
844+ options = element .query_selector_all ("option" )
845+ for found_option in options :
846+ if (
847+ "value" in found_option .attrs
848+ and str (found_option .attrs ["value" ]) == str (option )
849+ ):
850+ found_option .select_option ()
851+ return
852+ raise Exception (
853+ "Unable to find value option {%s} in dropdown {%s}!"
854+ % (dropdown_selector , option )
855+ )
856+
826857 def flash (
827858 self ,
828859 selector , # The CSS Selector to flash
0 commit comments