问题
I have a date in this format "21-Mar-2014"
I already tried to search for Xpath
formulas but with no use
I am getting the first format 21-Mar-2014
using SeleniumIDE
and want to check if this value is the date of today,
So how can xpath generate today's date and compare it for the date extracted using Selenium
回答1:
You can parse the string into a date with an xpath function such as date:date(string)
(described in this question).
Today's date already in xml date format is supplied by fn:current-date()
(see here)
回答2:
You can get the value, sore it in a variable, and then compare it. Eg:
storeText //xpath/goes/here myDate
storeEval (new Date(storedVars['myDate']) > new Date()) isAfterToday
Note, the storedVars
array holds all the variables.
new Date
should parse most formats, otherwise you can use any javascript in the storeEval
stage to reformat it.
来源:https://stackoverflow.com/questions/22552812/comparing-dates-in-xpath-with-different-formats