Comparing dates in Xpath with different formats

流过昼夜 提交于 2019-12-11 10:57:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!