Selecting a date value from a dynamically generated listbox.

Posted by ziggy on Stack Overflow See other posts from Stack Overflow or by ziggy
Published on 2010-06-15T13:51:20Z Indexed on 2010/06/15 13:52 UTC
Read the original article Hit count: 276

Filed under:
|

Hi All,

I have a listbox whose values are generated dynamically. The list box contains months and years and when generated looks like this.

<select name="arr_dtm_mon_year" tabindex="150" class="input">
<option value=""></option>
<option value="NOV 09">Nov 09</option>
<option value="DEC 09">Dec 09</option>
<option value="JAN 10">Jan 10</option>
<option value="FEB 10">Feb 10</option>
<option value="MAR 10">Mar 10</option>

<option value="APR 10">Apr 10</option>
<option value="MAY 10">May 10</option>
<option value="JUN 10" selected>Jun 10</option>
<option value="JUL 10">Jul 10</option>
<option value="AUG 10">Aug 10</option>
<option value="SEP 10">Sep 10</option>
<option value="OCT 10">Oct 10</option>
</select> 

The element in the listbox that is by default selected is the current month. When i use selenium IDE to select from this listbox it works fine. Here are example commands i use to select from the listbox.

<tr>
    <td>select</td>
<td>arr_dtm_mon_year</td>
<td>label=Oct 10</td>
</tr>
<tr>
<td>select</td>
<td>arr_dtm_mon_year</td>
<td>label=May 10</td>
</tr>

Now the problem i have is the values in the listbox is dynamically generated. In the above example i selected the option for "May 10". The values that are generated is a list of all previous six months and a list of all future six months.

This basically means that if i rerun the test 6 months from now "May 10" will not be available from the list. Is it possible to select the value dynamically. For example can i first calculate the current month and select the value with that is current month + 1 (i.e. next month). And also how can i build the value to be selected after i have determined what the next month is.

Any help will be greatly appreciated.

© Stack Overflow or respective owner

Related posts about testing

Related posts about selenium