Returns a list of select options as attribute text (configurable). @Params dropdown_selector - The selector of the "select" element. attribute - Choose from "text", "index", "value", or None (elements). by - The "by" of the "select" selector to use. Default: "css sele
(
self,
dropdown_selector,
attribute="text",
by="css selector",
timeout=None,
)
| 3274 | ) |
| 3275 | |
| 3276 | def get_select_options( |
| 3277 | self, |
| 3278 | dropdown_selector, |
| 3279 | attribute="text", |
| 3280 | by="css selector", |
| 3281 | timeout=None, |
| 3282 | ): |
| 3283 | """Returns a list of select options as attribute text (configurable). |
| 3284 | @Params |
| 3285 | dropdown_selector - The selector of the "select" element. |
| 3286 | attribute - Choose from "text", "index", "value", or None (elements). |
| 3287 | by - The "by" of the "select" selector to use. Default: "css selector". |
| 3288 | timeout - Wait time for "select". If None: settings.SMALL_TIMEOUT.""" |
| 3289 | self.wait_for_ready_state_complete() |
| 3290 | if not timeout: |
| 3291 | timeout = settings.SMALL_TIMEOUT |
| 3292 | if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT: |
| 3293 | timeout = self.__get_new_timeout(timeout) |
| 3294 | selector = dropdown_selector |
| 3295 | allowed_attributes = ["text", "index", "value", None] |
| 3296 | if attribute not in allowed_attributes: |
| 3297 | raise Exception("The attribute must be in %s" % allowed_attributes) |
| 3298 | selector, by = self.__recalculate_selector(selector, by) |
| 3299 | element = self.wait_for_element(selector, by=by, timeout=timeout) |
| 3300 | if element.tag_name.lower() != "select": |
| 3301 | raise Exception( |
| 3302 | 'Element tag_name for get_select_options(selector) must be a ' |
| 3303 | '"select"! Actual tag_name found was: "%s"' |
| 3304 | % element.tag_name.lower() |
| 3305 | ) |
| 3306 | if by != "css selector": |
| 3307 | selector = self.convert_to_css_selector(selector, by=by) |
| 3308 | option_selector = selector + " option" |
| 3309 | option_elements = self.find_elements(option_selector) |
| 3310 | if not attribute: |
| 3311 | return option_elements |
| 3312 | elif attribute == "text": |
| 3313 | return [e.text for e in option_elements] |
| 3314 | else: |
| 3315 | return [e.get_attribute(attribute) for e in option_elements] |
| 3316 | |
| 3317 | def load_html_string(self, html_string, new_page=True): |
| 3318 | """Loads an HTML string into the web browser. |