Take a value amount from a page and compare it with a fixed amount

Hi. This i want to ask, is if there is a way to read data from a webpage, for example to read a number on column which is not always the same , and to compare it with a fixed number.
If collected number is higher, then Kantu will open an url in new window.If amount is lower, then Kantu will open another url on new window.
I dont know how to read amounts from page and compare with fixed number.Thanks.

Hi @Panos, here’s a sample code to do what you need. To read amounts from a page, you can use the Select feature in Kantu to get the Target

select

{
  "Name": "findNumber",
  "CreationDate": "2019-9-12",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.google.com/search?q=random+number",
      "Value": ""
    },
    {
      "Command": "storeText",
      "Target": "xpath=//*[@id=\"Zv1Nfb\"]/div[1]",
      "Value": "varNumber"
    },
    {
      "Command": "echo",
      "Target": "${varNumber}",
      "Value": ""
    },
    {
      "Command": "if_v2",
      "Target": "${varNumber} > 5",
      "Value": ""
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=OPEN",
      "Value": "https://www.cbc.ca/news"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=OPEN",
      "Value": "https://www.macleans.ca"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}
1 Like

Thank you very much !
Just to confirm.So by this code we say to system "if variable is greater than 5 to open a new tab ? Also is there a symbol we can say to system “if variable is equal or greater” open the tab ? Thank you ! Appreciate your help !

I mean, what is the symbol not for greater ( > ) but for “equal or greater” ? Is it other symbol instead of > ?

Ok, that’s clear, thanks

== (equal)
!= (not equal)
>= (greater than or equal)
<= (less than or equal)
1 Like

Thank youuuu so much !! :smiley:

I’m glad to help. I’m fairly new here as well and users like @ulrich have been invaluable to this forum. So I’m glad that I can do my part and give back.

By the way, click the check mark on the post that answers your question so it is marked as resolved.

1 Like

Also there is another thing i need to ask.I want to tell to system , if TAB “cbc.ca” is already open if “{varNumber} > 5" to not open again other window but also to not refresh the existing cbc.ca . For example , after 1 minute the Kantu will refresh the page and will found again than "Target": "{varNumber} > 5” .But i dont want to open again “cbc.ca” if already is open.Only If not exist open, then i need to open.
On the other side, (on “else” command) when system find “Target”: “${varNumber} < 5” , then i want to open the alternative tab (www.macleans.ca) , but will close the “cbc.ca” tab if already is open.Is it possible ?

I want to open a tab , but if this Tab is already open (for example same Title Tab is open) then to not open again but just do nothing .If Tab Title is not open , then will open.Is it possible ?

Hi @Panos. This might be a little more involved. You might have to use a while loop and selectWindow and check the title of each one to see if the tab is already open.

I will write a sample code if I find some time.

Thank you very much William i will try from docs to use While commands ! :slight_smile: .

While is just looping the same command so opening again all time a new window.I think there is no solution to check if same tab is open so to not open again or not refresh again.

Hi William :slight_smile: .Do you know if is it possible to store a text as time value like xx:xx:xx and say for example to system if_v2 varNumber is higher than a fixed time value 00:15:20 then do action?

Hey :slight_smile: I want to write this “Command”: “if_v2”,
“Target”: “{Variable1} > [{Variable2}+200]” but not working.Is comparing only variable1 with variable2 and ignores the 200.Do you know how i should write it ?

Hi @Panos, apologies for the non-reply. I’ve been tied up. I think I saw you post this elsewhere @ulrich has helped you. Is that correct?

Hi William :slight_smile: .I used the first solution but i think Urlich solution is easiest and better.I didnt use it yet but i will test it now.I let you know results but i am 100% sure it will work :slight_smile: .

Yes all works fine :wink: