@@ -2585,6 +2585,47 @@ def select_option_by_value(
2585
2585
timeout=timeout,
2586
2586
)
2587
2587
2588
+ def get_select_options(
2589
+ self,
2590
+ dropdown_selector,
2591
+ attribute="text",
2592
+ by="css selector",
2593
+ timeout=None,
2594
+ ):
2595
+ """Returns a list of select options as attribute text (configurable).
2596
+ @Params
2597
+ dropdown_selector - The selector of the "select" element.
2598
+ attribute - Choose from "text", "index", "value", or None (elements).
2599
+ by - The "by" of the "select" selector to use. Default: "css selector".
2600
+ timeout - Time to wait for "select". If None: settings.SMALL_TIMEOUT.
2601
+ """
2602
+ self.wait_for_ready_state_complete()
2603
+ if not timeout:
2604
+ timeout = settings.SMALL_TIMEOUT
2605
+ if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
2606
+ timeout = self.__get_new_timeout(timeout)
2607
+ selector = dropdown_selector
2608
+ allowed_attributes = ["text", "index", "value", None]
2609
+ if attribute not in allowed_attributes:
2610
+ raise Exception("The attribute must be in %s" % allowed_attributes)
2611
+ selector, by = self.__recalculate_selector(selector, by)
2612
+ element = self.wait_for_element(selector, by=by, timeout=timeout)
2613
+ if element.tag_name != "select":
2614
+ raise Exception(
2615
+ 'Element tag_name for get_select_options(selector) must be a '
2616
+ '"select"! Actual tag_name found was: "%s"' % element.tag_name
2617
+ )
2618
+ if by != "css selector":
2619
+ selector = self.convert_to_css_selector(selector, by=by)
2620
+ option_selector = selector + " option"
2621
+ option_elements = self.find_elements(option_selector)
2622
+ if not attribute:
2623
+ return option_elements
2624
+ elif attribute == "text":
2625
+ return [e.text for e in option_elements]
2626
+ else:
2627
+ return [e.get_attribute(attribute) for e in option_elements]
2628
+
2588
2629
def load_html_string(self, html_string, new_page=True):
2589
2630
"""Loads an HTML string into the web browser.
2590
2631
If new_page==True, the page will switch to: "data:text/html,"
0 commit comments