0

So I'm using

<tr> 
    <td>storeEval</td> 
    <td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1)) 
+'-'+d.getFullYear();</td> 
    <td>date2</td> 
</tr>
<tr>
    <td>storeValue</td>
    <td>//span[@id=&quot;txtDateEnd&quot;]//input[@id=&quot;txtDateEnd_txt&quot;]</td>
    <td>Date1</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>&quot;${Date1}&quot; &gt; &quot;${Date2}&quot;</td>
    <td>Test</td>
</tr>

from Selenium IDE: How do I get today's date?

However I want to compare two date one of which is registered directly from a xpath on my page. Fact is Selenium does not recognize these values as date format and simply try to compare the raw number togueter. I have been looking around for the proper syntax to register these value as dates rather then raw number so that when I compare "${Date1}" > "${Date2}" the number are compared as dates rather then as raw numbers.

  • 1
    Check the following link, might be helpful for you : https://stackoverflow.com/questions/22552812/comparing-dates-in-xpath-with-different-formats – anshul Gupta Jun 19 '17 at 15:47

1 Answers1

0

As suggested in the link shown above I used the 'new Date' line to force selenium into recognising those variable as dates. furthermore I managed to resume the entire script to a single line as:

<tr>
    <td>storeEval</td>
    <td>(new Date() &gt; new Date(selenium.getValue('//span[@id=&quot;txtDateEnd&quot;]//input[@id=&quot;txtDateEnd_txt&quot;]')))</td>
    <td>CouponExpired</td>
</tr>

Thanks again for the link much appreciated.