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

Method SelectByIndex

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

Select the option by the index, as determined by the "index" attribute of the element. The value of the index attribute of the option to be selected. Thrown when no element exists with the specified index attribute.

(int index)

Source from the content-addressed store, hash-verified

231 /// <param name="index">The value of the index attribute of the option to be selected.</param>
232 /// <exception cref="NoSuchElementException">Thrown when no element exists with the specified index attribute.</exception>
233 public void SelectByIndex(int index)
234 {
235 string match = index.ToString(CultureInfo.InvariantCulture);
236
237 foreach (IWebElement option in this.Options)
238 {
239 if (option.GetAttribute("index") == match)
240 {
241 SetSelected(option, true);
242 return;
243 }
244 }
245
246 throw new NoSuchElementException("Cannot locate option with index: " + index);
247 }
248
249 /// <summary>
250 /// Clear all selected entries. This is only valid when the SELECT supports multiple selections.

Calls 2

ToStringMethod · 0.45
GetAttributeMethod · 0.45