org.openqa.selenium.support.ui
Class Select

java.lang.Object
  extended by org.openqa.selenium.support.ui.Select

public class Select
extends Object

Models a SELECT tag, providing helper methods to select and deselect options.


Constructor Summary
Select(WebElement element)
          Constructor.
 
Method Summary
 void deselectAll()
          Clear all selected entries.
 void deselectByIndex(int index)
          Deselect the option at the given index.
 void deselectByValue(String value)
          Deselect all options that have a value matching the argument.
 void deselectByVisibleText(String text)
          Deselect all options that display text matching the argument.
protected  String escapeQuotes(String toEscape)
           
 List<WebElement> getAllSelectedOptions()
           
 WebElement getFirstSelectedOption()
           
 List<WebElement> getOptions()
           
 boolean isMultiple()
           
 void selectByIndex(int index)
          Select the option at the given index.
 void selectByValue(String value)
          Select all options that have a value matching the argument.
 void selectByVisibleText(String text)
          Select all options that display text matching the argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Select

public Select(WebElement element)
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 Detail

isMultiple

public boolean isMultiple()
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

public List<WebElement> getOptions()
Returns:
All options belonging to this select tag

getAllSelectedOptions

public List<WebElement> getAllSelectedOptions()
Returns:
All selected options belonging to this select tag

getFirstSelectedOption

public WebElement getFirstSelectedOption()
Returns:
The first selected option in this select tag (or the currently selected option in a normal select)

selectByVisibleText

public void selectByVisibleText(String text)
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>

Parameters:
text - The visible text to match against

selectByIndex

public void selectByIndex(int index)
Select the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting.

Parameters:
index - The option at this index will be selected

selectByValue

public void selectByValue(String value)
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>

Parameters:
value - The value to match against

deselectAll

public void deselectAll()
Clear all selected entries. This is only valid when the SELECT supports multiple selections.

Throws:
UnsupportedOperationException - If the SELECT does not support multiple selections

deselectByValue

public void deselectByValue(String value)
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>

Parameters:
value - The value to match against

deselectByIndex

public void deselectByIndex(int index)
Deselect the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting.

Parameters:
index - The option at this index will be deselected

deselectByVisibleText

public void deselectByVisibleText(String text)
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>

Parameters:
text - The visible text to match against

escapeQuotes

protected String escapeQuotes(String toEscape)


Copyright © 2011. All Rights Reserved.