Package org.openqa.selenium.support.ui
Class Select
java.lang.Object
org.openqa.selenium.support.ui.Select
- All Implemented Interfaces:
ISelect,WrapsElement
Models a SELECT tag, providing helper methods to select and deselect options.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear all selected entries.voidvoiddeselectByIndex(int index) Deselect the option at the given index.voiddeselectByValue(String value) Deselect all options that have a value matching the argument.voiddeselectByVisibleText(String text) Deselect all options that display text matching the argument.booleaninthashCode()booleanvoidSelects all options that display text matching or containing the provided argument.voidselectByIndex(int index) Select the option at the given index.voidselectByValue(String value) Select all options that have a value matching the argument.voidselectByVisibleText(String text) Select all options that display text matching the argument.
-
Constructor Details
-
Select
Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.- Parameters:
element- SELECT element to wrap- Throws:
UnexpectedTagNameException- when element is not a SELECT
-
-
Method Details
-
getWrappedElement
- Specified by:
getWrappedElementin interfaceWrapsElement
-
isMultiple
public boolean isMultiple()- Specified by:
isMultiplein interfaceISelect- Returns:
- Whether this select element support selecting multiple options at the same time? This is done by checking the value of the "multiple" attribute.
-
getOptions
- Specified by:
getOptionsin interfaceISelect- Returns:
- All options belonging to this select tag
-
getAllSelectedOptions
- Specified by:
getAllSelectedOptionsin interfaceISelect- Returns:
- All selected options belonging to this select tag
-
getFirstSelectedOption
- Specified by:
getFirstSelectedOptionin interfaceISelect- Returns:
- The first selected option in this select tag (or the currently selected option in a normal select)
- Throws:
NoSuchElementException- If no option is selected
-
selectByVisibleText
Select all options that display text matching the argument. That is, when given "Bar" this would select an option like:<option value="foo">Bar</option>
- Specified by:
selectByVisibleTextin interfaceISelect- Parameters:
text- The visible text to match against- Throws:
NoSuchElementException- If no matching option elements are found
-
selectByContainsVisibleText
Selects all options that display text matching or containing the provided argument. This method first attempts to find an exact match and, if not found, will then attempt to find options that contain the specified text as a substring.For example, when given "Bar", this would select an option like:
<option value="foo">Bar</option>
And also select an option like:
<option value="baz">FooBar</option> or <option value="baz">1년납</option> when "1년" is provided.
- Specified by:
selectByContainsVisibleTextin interfaceISelect- Parameters:
text- The visible text to match against. It can be a full or partial match of the option text.- Throws:
NoSuchElementException- If no matching option elements are found
-
selectByIndex
public void selectByIndex(int index) Select the option at the given index. This is done by examining the "index" attribute of an element, and not merely by counting.- Specified by:
selectByIndexin interfaceISelect- Parameters:
index- The option at this index will be selected- Throws:
NoSuchElementException- If no matching option elements are found
-
selectByValue
Select all options that have a value matching the argument. That is, when given "foo" this would select an option like:<option value="foo">Bar</option>
- Specified by:
selectByValuein interfaceISelect- Parameters:
value- The value to match against- Throws:
NoSuchElementException- If no matching option elements are found
-
deselectAll
public void deselectAll()Clear all selected entries. This is only valid when the SELECT supports multiple selections.- Specified by:
deselectAllin interfaceISelect- Throws:
UnsupportedOperationException- If the SELECT does not support multiple selections
-
deselectByValue
Deselect all options that have a value matching the argument. That is, when given "foo" this would deselect an option like:<option value="foo">Bar</option>
- Specified by:
deselectByValuein interfaceISelect- Parameters:
value- The value to match against- Throws:
NoSuchElementException- If no matching option elements are foundUnsupportedOperationException- If the SELECT does not support multiple selections
-
deselectByIndex
public void deselectByIndex(int index) Deselect the option at the given index. This is done by examining the "index" attribute of an element, and not merely by counting.- Specified by:
deselectByIndexin interfaceISelect- Parameters:
index- The option at this index will be deselected- Throws:
NoSuchElementException- If no matching option elements are foundUnsupportedOperationException- If the SELECT does not support multiple selections
-
deselectByVisibleText
Deselect all options that display text matching the argument. That is, when given "Bar" this would deselect an option like:<option value="foo">Bar</option>
- Specified by:
deselectByVisibleTextin interfaceISelect- Parameters:
text- The visible text to match against- Throws:
NoSuchElementException- If no matching option elements are foundUnsupportedOperationException- If the SELECT does not support multiple selections
-
deSelectByContainsVisibleText
- Specified by:
deSelectByContainsVisibleTextin interfaceISelect
-
equals
-
hashCode
public int hashCode()
-