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

Method deselect_by_value

py/selenium/webdriver/support/select.py:159–182  ·  view source on GitHub ↗

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

(self, value: str)

Source from the content-addressed store, hash-verified

157 self._unset_selected(opt)
158
159 def deselect_by_value(self, value: str) -> None:
160 """Deselect all options that have a value matching the argument.
161
162 Example:
163 When given "foo" this would deselect an option like:
164
165 `<option value="foo">Bar</option>`
166
167 Args:
168 value: The value to match against
169
170 Raises:
171 NoSuchElementException: If there is no option with specified value in SELECT
172 """
173 if not self.is_multiple:
174 raise NotImplementedError("You may only deselect options of a multi-select")
175 matched = False
176 css = f"option[value = {self._escape_string(value)}]"
177 opts = self._el.find_elements(By.CSS_SELECTOR, css)
178 for opt in opts:
179 self._unset_selected(opt)
180 matched = True
181 if not matched:
182 raise NoSuchElementException(f"Could not locate element with value: {value}")
183
184 def deselect_by_index(self, index: int) -> None:
185 """Deselect the option at the given index by examining the "index" attribute.

Calls 4

_escape_stringMethod · 0.95
_unset_selectedMethod · 0.95
find_elementsMethod · 0.45