views:

349

answers:

2

The problem is the option labels change and so I cant grab by label. I need to grab by say option[0]

any idea?

I'm using Selenium IDE (Firefox), this is the piece im asking about:

<tr>
    <td>select</td>
    <td>dateRangeString</td>
    <td>index=1</td>
</tr>

the last TD there is the VALUE field in the IDE,

I already am targeting the select element, but i need to simulate the user selecting the first option. The only way I see to do this is by using LABEL="string" in the VALUE part of the IDE, but string is dynamic so thats not going to work!

+2  A: 

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.

AutomatedTester
I think you misunderstand what my needs are. I already am targeting the select element, but i need to simulate the user selecting the first option. The only way I see to do this is by using LABEL="label string" in the VALUE part of the IDE
codeninja
updated my answer with the extra info from the question
AutomatedTester
Yeah I figured out how to use index=index before you posted your update =] I had that initially but it didnt seem to work. I had to do some wait command. But thanks for the full info. Do you know where you can find documentation for this some place?
codeninja
A: 

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

David