MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / select_by_index

Method select_by_index

py/selenium/webdriver/support/select.py:87–101  ·  view source on GitHub ↗

Select the option at the given index by examining the "index" attribute. Args: index: The option at this index will be selected Raises: NoSuchElementException: If there is no option with specified index in SELECT

(self, index: int)

Source from the content-addressed store, hash-verified

85 raise NoSuchElementException(f"Cannot locate option with value: {value}")
86
87 def select_by_index(self, index: int) -> None:
88 """Select the option at the given index by examining the "index" attribute.
89
90 Args:
91 index: The option at this index will be selected
92
93 Raises:
94 NoSuchElementException: If there is no option with specified index in SELECT
95 """
96 match = str(index)
97 for opt in self.options:
98 if opt.get_attribute("index") == match:
99 self._set_selected(opt)
100 return
101 raise NoSuchElementException(f"Could not locate element with index {index}")
102
103 def select_by_visible_text(self, text: str) -> None:
104 """Select all options that display text matching the argument.

Calls 3

_set_selectedMethod · 0.95
get_attributeMethod · 0.80