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

Method DeselectByText

dotnet/src/support/UI/SelectElement.cs:279–301  ·  view source on GitHub ↗

Deselect the option by the text displayed. Thrown when attempting to deselect option from a SELECT that does not support multiple selections. Thrown when no element exists with the specified test attribute. The text of the option to be deselected.</pa

(string text)

Source from the content-addressed store, hash-verified

277 /// </para>
278 /// </remarks>
279 public void DeselectByText(string text)
280 {
281 if (!this.IsMultiple)
282 {
283 throw new InvalidOperationException("You may only deselect option if multi-select is supported");
284 }
285
286 bool matched = false;
287 StringBuilder builder = new StringBuilder(".//option[normalize-space(.) = ");
288 builder.Append(EscapeQuotes(text));
289 builder.Append("]");
290 IList<IWebElement> options = this.WrappedElement.FindElements(By.XPath(builder.ToString()));
291 foreach (IWebElement option in options)
292 {
293 SetSelected(option, false);
294 matched = true;
295 }
296
297 if (!matched)
298 {
299 throw new NoSuchElementException("Cannot locate option with text: " + text);
300 }
301 }
302
303 /// <summary>
304 /// Deselect the option having value matching the specified text.

Calls 3

XPathMethod · 0.80
FindElementsMethod · 0.45
ToStringMethod · 0.45