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

Method select_by_value

py/selenium/webdriver/support/select.py:62–85  ·  view source on GitHub ↗

Select all options that have a value matching the argument. Example: When given "foo" this would select an option like: ` Bar ` Args: value: The value to match against Raises: NoSuchElementExce

(self, value: str)

Source from the content-addressed store, hash-verified

60 raise NoSuchElementException("No options are selected")
61
62 def select_by_value(self, value: str) -> None:
63 """Select all options that have a value matching the argument.
64
65 Example:
66 When given "foo" this would select an option like:
67
68 `<option value="foo">Bar</option>`
69
70 Args:
71 value: The value to match against
72
73 Raises:
74 NoSuchElementException: If there is no option with specified value in SELECT
75 """
76 css = f"option[value ={self._escape_string(value)}]"
77 opts = self._el.find_elements(By.CSS_SELECTOR, css)
78 matched = False
79 for opt in opts:
80 self._set_selected(opt)
81 if not self.is_multiple:
82 return
83 matched = True
84 if not matched:
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.

Calls 4

_escape_stringMethod · 0.95
_set_selectedMethod · 0.95
find_elementsMethod · 0.45