Kantu Selenium - date in calendar automatically adjusting

Automating date controls can be tricky. I suggest to use computer vision for this. In the macro below I

  • open the date selector
  • limit the computer vision area to the date control area
  • let Kantu find and click the number for the date e. g. “22” or “17” with XClick | OCR=text

Here is a screencast of the macro running:

The cal1.png to limit the search area is:

cal1

Macro code:

{
  "Name": "Date Control Automation",
  "CreationDate": "2019-3-22",
  "Commands": [
    {
      "Command": "open",
      "Target": "http://ems.rs/page.php?kat_id=260",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "rus",
      "Value": "!OCRlanguage"
    },
    {
      "Command": "XClick",
      "Target": "ocr=Дан",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Area top left corner = bottom left corner of found image ",
      "Value": ""
    },
    {
      "Command": "visualAssert",
      "Target": "cal1.png",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${!imagex}-${!imagewidth}/2",
      "Value": "x1"
    },
    {
      "Command": "storeEval",
      "Target": "${!imagey}-${!imageheight}/2",
      "Value": "y1"
    },
    {
      "Command": "comment",
      "Target": "Area bottom right corner",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${!imagex}+${!imagewidth}/2",
      "Value": "x2"
    },
    {
      "Command": "storeEval",
      "Target": "${!imagey}+${!imageheight}/2",
      "Value": "y2"
    },
    {
      "Command": "echo",
      "Target": "x1=${x1}, y1=${y1}, x2=${x2}, y2=${y2}",
      "Value": "blue"
    },
    {
      "Command": "visionLimitSearchArea",
      "Target": "area=${x1},${y1},${x2},${y2}",
      "Value": ""
    },
    {
      "Command": "XClick",
      "Target": "ocr=[22]",
      "Value": ""
    }
  ]
}

Update 2024: RPA V9.2.0 and newer: We improved the text search and introduced wildcard support (* and ?). Now the search behaves like a standard text search on Windows. The default text match mode is exact match: “OCRSearch | day” matches “day” but not “today” or “yesterday’s”. For a partial text match use *day*. So OCRSearch | *day* matches “day” and also “today” and “yesterday’s”.

=> In the demo macro above you need to replace

XClick |ocr=[22]

with

XClickText | 22