This task is possible. It consists of 3 parts:
-
Extract the date from the website. For this, you use storeText (extract date from html text) or storeValue (get date from input box). This is described in more detail in this get data from salesforce post.
-
Compare the dates - this part is a bit tricky and requires storeEval and Javascript, see below.
-
If it is a past date, click on the link. This should be easy to solve it, you only need to find the right locator for the link to click on.
So the open, tricky topic is number, compare the dates.
For dates in the US format mm/dd/yyyy the compare logic in Javascript is:
var dateString1 = "${d1}"; var dateParts1 = dateString1.split("/"); var dateObject1 = new Date(dateParts1[2], dateParts1[0] - 1, dateParts1[1]); var dateString2 = "${d2}"; var dateParts2 = dateString2.split("/"); var dateObject2 = new Date(dateParts2[2], dateParts2[0] - 1, dateParts2[1]); dateObject2 > dateObject1
For dates in the EU format dd/mm/yyyy the compare logic in Javascript is this (same as above, just day and month exchanged):
var dateString1 = "${d1}"; var dateParts1 = dateString1.split("/"); var dateObject1 = new Date(dateParts1[2], dateParts1[1] - 1, dateParts1[0]); var dateString2 = "${d2}"; var dateParts2 = dateString2.split("/"); var dateObject2 = new Date(dateParts2[2], dateParts2[1] - 1, dateParts2[0]); dateObject2 > dateObject1
What this snippet does is to split the string with / and put day, month and year in an array. Then recombine the string in the yyyy-mm-dd format that the Javascript date function needs. It does this twice, once for the first date ${d1}
and then for the second date ${d2}
, and then compare the dates with dateObject2 > dateObject1
Complete test macro for part 2 date comparison:
{
"CreationDate": "2018-5-29",
"Commands": [
{
"Command": "store",
"Target": "05/25/2018",
"Value": "d1"
},
{
"Command": "store",
"Target": "05/29/2018",
"Value": "d2"
},
{
"Command": "echo",
"Target": "d1=${d1}",
"Value": "blue"
},
{
"Command": "echo",
"Target": "d2=${d2}",
"Value": "blue"
},
{
"Command": "storeEval",
"Target": "var dateString1 = \"${d1}\"; var dateParts1 = dateString1.split(\"/\"); var dateObject1 = new Date(dateParts1[2], dateParts1[0] - 1, dateParts1[1]); var dateString2 = \"${d2}\"; var dateParts2 = dateString2.split(\"/\"); var dateObject2 = new Date(dateParts2[2], dateParts2[0] - 1, dateParts2[1]); dateObject2 > dateObject1",
"Value": "IsD2Later"
},
{
"Command": "echo",
"Target": "Is Date 2 Later => ${IsD2Later}",
"Value": "green"
},
{
"Command": "if",
"Target": "${IsD2Later}",
"Value": ""
},
{
"Command": "echo",
"Target": "do something, D2 is later ",
"Value": "orange"
},
{
"Command": "else",
"Target": "",
"Value": ""
},
{
"Command": "echo",
"Target": "D2 earlier, do something else",
"Value": "red"
},
{
"Command": "endif",
"Target": "",
"Value": ""
}
]
}
Screenshot: