Dropdown Elements
Overview
Dropdowns are comprised of two element types:
Watir::Select
and
Watir::Option
These are accessed by calling Browser#select
or Browser#select_list
.
Creating a SelectCollection
is accomplished with Browser#selects
or Browser#select_lists
,
and an OptionColection
by Browser#options
or Select#options
.
For all of the different ways of locating a Select
element,
take a look at our Locating Elements Guide.
Note that Option
elements should generally be accessed via a Select
element instance.
Browser Drivers treat Option
elements differently than other elements.
They are the only element type that does not need to be displayed on the page in order to
click them. That means you do not have to first click the Select
element to use it.
Note that there are a many Dropdown implementation that combine JavaScript with non-standard elements to achieve this affect. Because these elements are not handled in the same way as Option and Select elements, they can not be treated as Dropdowns by Watir.
Select
and Option
elements also inherit methods from standard Web Elements
Common or Special Methods
Select#include?
Select#select
Select#text
Select#value
Select#clear
- this only applies if the checklist has amultiple
attribute
Standard Setter Interface
This functionality was added in Watir 7 beta 2.
Select#set
is an alias of #select
. It takes a number of different argument types:
- When the first parameter value is a
String
or aRegexp
, Watir will select the firstOption
that matches byvalue
,text
orlabel
attributes. - When the first parameter is a value is a
Numeric
, Watir will convert it to a String and select the firstOption
that matches by value, text or label. - When the
:value
,:text
or:label
keywords are used, Watir will select the firstOption
that matches on that particular attribute. - When an
Array
or multiple parameters are passed in, Watir treats theSelect
object as having the attributemultiple
, and will select everyOption
that matches each value in theArray
byvalue
,text
orlabel
attributes.