Kantu Selenium - date in calendar automatically adjusting

Hey guys,

I’m trying to automatize daily work I do as much as possible. For that purpose I found this Kantu Web Automation tool, but along the way I stumbled upon several problems :

  1. one file I’m downloading every day is uploaded behind corresponding date in calendar, that means that each day alghoritm should recognize the date and click on it. How could this be done ? site: EMС АД | Електромрежа Србије photo:

or site: Auctions | JAO S.A. Leading service provider for TSOs photo:

  1. also im trying to copy text data from a specific part of a site and selenium recognizes when I mark the text, but I couldn’t copy it to the clipboard. Is there a way to do this ?

Thank you very much for any help in advance, looking forward for your answers.

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": ""
    }
  ]
}

Do yo want to copy the content to the clipboard?

You can use XType to send a

  • Ctrl+S to save the page
  • or Ctrl+A and Ctrl+C to mark everything and copy it

or use web scraping

If you have more questions about the extracting the table, best to make a new forum post. So we can limit this one to the date control question.

Hey man,

Thank you so much, you helped me a ton. I just have one more problem with this, how could I change automatically dates (numbers basically) that I search for in calendar. So today would be 25, tommorow 26 and in five days one again.

Is there a function that returns todays date, time or something like that ? Thank you again !

Sure. See storeEval and the example Javascript snippets. For example:

var d= new Date(); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate(); => Get todays date in YYYY-MM-DD format

Hi @Plankton

It’s possibile to change the date format ?

example from YYYY-MM-DD to DD-MM-YYYY ?

If yes how can i change the date format please?

Have a nice day

You can change the date format to DD-MM-YYYY by changing this part of my Javascript code:

d.getFullYear()+"-"+m+"-"+d.getDate();

to

d.getDate() +"-"+m+"-"+ d.getFullYear() ;

Thanks @Plankton

Have a nice day

Hey guys, since April this code is not working anymore. First problem was OCR detecting part of the screen where calendar is .
When I made a new printscreen to put april it started to detect it again, but this is not complete solution because every month I would need to chage image. Any ideas how to resolve this ?

Other problem is that it is not detecting dates at all. I tried anything but it doest detect them ?

Full code here :

{
  "Name": "EMS1 - Mađarska",
  "CreationDate": "2019-4-11",
  "Commands": [
    {
      "Command": "open",
      "Target": "http://ems.rs/page.php?kat_id=260",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "new Date().getDate()+1",
      "Value": "mydate"
    },
    {
      "Command": "click",
      "Target": "/html/body/div/div/div[3]/div[1]/div[1]/h3/span[1]",
      "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": "ddsmer_dpi_96.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=${mydate}",
      "Value": ""
    },
    {
      "Command": "selectFrame",
      "Target": "index=0",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "/html/body/div[1]/div[1]/div[2]/div[3]",
      "Value": ""
    },
    {
      "Command": "type",
      "Target": "id=format1",
      "Value": "CSV"
    },
    {
      "Command": "click",
      "Target": "/html/body/div[1]/div[2]/div[3]/div/div[4]/div/label[1]",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "id=format1",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "link=Преузми",
      "Value": ""
    }
  ]
}

Updating the question. After long checking, it seems that the problem is with OCR.

It detects correctly a date when I have March in the calendar, but it gets confused with April or May.

Here are the photos :


Could you please tell why is this happening? It is so odd since all these numbers look basically the same.

I think the problem is here:

{
  "Command": "XClick",
  "Target": "ocr=${mydate}",
  "Value": ""
},

It should be

{
  "Command": "XClick",
  "Target": "ocr=[${mydate}]",
  "Value": ""
},

The difference are the […] for exact match. Exact text match (= whole word match) is useful, for example, when automating a date control. There will be the numbers 8,18,28. With ocr=8 it might match and click 8 or 18 or 28!!!

With ocr=[8] you make sure that only the number 8 is clicked, and not 18 or 28.

1 Like

Highly recommend that you could use Executescript to remove the attribute (“readonly”) of the Calendar element, then you can Type the date (with correct formart) in easily.