Suyog Sakegaonkar
Suyog Sakegaonkar

Reputation: 225

How to automate DatePicker in Selenium IDE?

<tr>
    <td>type</td>
    <td>id=release_date</td>
    <td>2012-09-30</td>
</tr>

This works but I don't want to type the date but pick it using DatePicker and try automating it.

Upvotes: 3

Views: 7671

Answers (2)

Nedko Hristov
Nedko Hristov

Reputation: 31

As newbie in Selenium IDE these days I done some tests who includes the date picker too.

I'll paste my HTML code, but if you have any problems or anything feel free to ask.

<!--Set some random generators for Hour From/To-->
<tr>
    <td>storeEval</td>
    <td>[Math.floor((Math.random() * 31) + 1)]</td>
    <td>random</td>
</tr>
<tr>
    <td>click</td>
    <td>//select[@id='valid']/option[3]</td>
    <td></td>
</tr>
<!--Add values to From date and To date-->
<tr>
    <td>click</td>
    <td>id=p_date_from</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=${random}</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//div[@id='valid_period']/p[2]/span/span/abbr</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>[Math.floor((Math.random() * 10) + 1)]</td>
    <td>random</td>
</tr>
<tr>
    <td>click</td>
    <td>link=${random}</td>
    <td></td>
</tr>

Upvotes: 1

Mark Kimitch
Mark Kimitch

Reputation: 332

This will vary greatly depending on how your datepicker is coded. For example, I'm working on a Web app that utilizes Dojo and I'm using the following code to select a specific position within the datepicker pop-up instead of a particular date (because the actual date isn't important for my tests):

<tr>
    <td>waitForElementPresent</td>
    <td>//*[@id=&quot;startDate&quot;]</td>
    <td></td>
</tr>
<tr>
    <td>clickAt</td>
    <td>xpath=(//input[@value='▼ '])[3]</td>
    <td></td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>//table[@id='startDate_popup']/tbody/tr/td[4]/span</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//table[@id='startDate_popup']/tbody/tr/td[4]/span</td>
    <td></td>
</tr>

I use waitForElementPresent frequently to make sure the JavaScript has time to complete running before the next step in the test is executed.

I've also found that clickAt is useful when clicking within Dojo widgets, and I typically prefer to use XPath for specific targets.

I hope this helps!

Upvotes: 6

Related Questions