use storeEval
Below is an example of a fully working selenium test that exactly matches your requirements, to run it by opening the IDE, click the Source tab in the main window and paste the code between the <tbody>
<tr> <td>open</td> <td>http://www.plus2net.com/php_tutorial/date-selection.php</td> <td></td> </tr> <tr> <td>storeEval</td> <td>new Date().setDate( new Date().getDate() + 31);</td> <td>date</td> </tr> <tr> <td>echo</td> <td>${date}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31); d=d.getFullYear()</td> <td>year</td> </tr> <tr> <td>type</td> <td>name=year</td> <td>${year}</td> </tr> <tr> <td>echo</td> <td>${year}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31); d=d.getMonth() + 1</td> <td>month</td> </tr> <tr> <td>select</td> <td>name=month</td> <td>value=${month}</td> </tr> <tr> <td>echo</td> <td>${month}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31).getDate(); d= d.toString().length == 1 ? "0" + d : d;</td> <td>day</td> </tr> <tr> <td>select</td> <td>name=dt</td> <td>label=${day}</td> </tr> <tr> <td>echo</td> <td>${day}</td> <td></td> </tr>
I added in javascript to return a date of 31 days in the future.
You can also use a combination of runScript and storeEval to get almost any information from the page.
The question I asked demonstrates the idea
Download an external js file containing useful test functions in selenium
Any other questions will add a comment and I will be happy to help :)
See @ icc97 comment for adding zero padding to dates.
chim
source share