In Selenium IDE how can you select an option by index in a dropdown menu?
you can select it by using the XPath //select/option[index]
.
Remember that XPath is a 1 based index by standard.
Edit After Question was updated
You can use a number of different ways to select an option from within a select. Below has been copied from the Selenium IDE on how to create option locators. To select the first item it would be index=0
select(selectLocator, optionLocator) Arguments:
* selectLocator - an element locator identifying a drop-down menu * optionLocator - an option locator (a label by default)Select an option from a drop-down using an option locator.Option locators provide different ways of specifying options of an HTML
Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
* label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.) o label=regexp:^[Oo]ther * value=valuePattern: matches options based on their values. o value=other * id=id: matches options based on their ids. o id=option1 * index=index: matches an option based on its index (offset from zero). o index=2
If no option locator prefix is provided, the default behaviour is to
match on label.
Instead of using label="", try using index="1" (to select the first element). Selenium offers label="", id="", value="", and index="" for this sort of cases. For more details, see:
http://release.seleniumhq.org/selenium-core/0.8.0/reference.html
Tricky, but the "type" command helped me here:
<tr> <td>type</td> <td>id=numStuff</td> <td>1</td></tr>
The corresponding html looks like this (except the @id and @name attributes)
<select id="numStuff" name="numStuff"> <option selected= value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option></select>
I'm wondering if it works for option values longer than 1 keystroke. At least, it's good for the time being.