Class SelectElement
Provides a convenience method for manipulating selections of options in an HTML select element.
public class SelectElement : IWrapsElement
- Inheritance
-
SelectElement
- Implements
- Inherited Members
Constructors
SelectElement(IWebElement)
Initializes a new instance of the SelectElement class.
public SelectElement(IWebElement element)
Parameters
element
IWebElementThe element to be wrapped
Exceptions
- ArgumentNullException
Thrown when the IWebElement object is null
- UnexpectedTagNameException
Thrown when the element wrapped is not a <select> element.
Properties
AllSelectedOptions
Gets all of the selected options within the select element.
public IList<IWebElement> AllSelectedOptions { get; }
Property Value
IsMultiple
Gets a value indicating whether the parent element supports multiple selections.
public bool IsMultiple { get; }
Property Value
Options
Gets the list of options for the select element.
public IList<IWebElement> Options { get; }
Property Value
SelectedOption
Gets the selected item within the select element.
public IWebElement SelectedOption { get; }
Property Value
Remarks
If more than one item is selected this will return the first item.
Exceptions
- NoSuchElementException
Thrown if no option is selected.
WrappedElement
Gets the IWebElement wrapped by this object.
public IWebElement WrappedElement { get; }
Property Value
Methods
DeselectAll()
Clear all selected entries. This is only valid when the SELECT supports multiple selections.
public void DeselectAll()
Exceptions
- WebDriverException
Thrown when attempting to deselect all options from a SELECT that does not support multiple selections.
DeselectByIndex(int)
Deselect the option by the index, as determined by the "index" attribute of the element.
public void DeselectByIndex(int index)
Parameters
index
intThe value of the index attribute of the option to deselect.
Exceptions
- InvalidOperationException
Thrown when attempting to deselect option from a SELECT that does not support multiple selections.
- NoSuchElementException
Thrown when no element exists with the specified index attribute.
DeselectByText(string)
Deselect the option by the text displayed.
public void DeselectByText(string text)
Parameters
text
stringThe text of the option to be deselected.
Remarks
When given "Bar" this method would deselect an option like:
<option value="foo">Bar</option>
Exceptions
- InvalidOperationException
Thrown when attempting to deselect option from a SELECT that does not support multiple selections.
- NoSuchElementException
Thrown when no element exists with the specified test attribute.
DeselectByValue(string)
Deselect the option having value matching the specified text.
public void DeselectByValue(string value)
Parameters
value
stringThe value of the option to deselect.
Remarks
When given "foo" this method will deselect an option like:
<option value="foo">Bar</option>
Exceptions
- InvalidOperationException
Thrown when attempting to deselect option from a SELECT that does not support multiple selections.
- NoSuchElementException
Thrown when no element exists with the specified value attribute.
SelectByIndex(int)
Select the option by the index, as determined by the "index" attribute of the element.
public void SelectByIndex(int index)
Parameters
index
intThe value of the index attribute of the option to be selected.
Exceptions
- NoSuchElementException
Thrown when no element exists with the specified index attribute.
SelectByText(string, bool)
Select all options by the text displayed.
public void SelectByText(string text, bool partialMatch = false)
Parameters
text
stringThe text of the option to be selected.
partialMatch
boolDefault value is false. If true a partial match on the Options list will be performed, otherwise exact match.
Remarks
When given "Bar" this method would select an option like:
<option value="foo">Bar</option>
Exceptions
- ArgumentNullException
If
text
is null.- NoSuchElementException
Thrown if there is no element with the given text present.
SelectByValue(string)
Select an option by the value.
public void SelectByValue(string value)
Parameters
value
stringThe value of the option to be selected.
Remarks
When given "foo" this method will select an option like:
<option value="foo">Bar</option>
Exceptions
- NoSuchElementException
Thrown when no element with the specified value is found.