Checking an element value


#1

Hi, I would like to check the value of an element and compare that to a number I define in the script. In example I would like to get the value of this element (its a decimal like 1.76) and compare that to the number 5. If it is greater, I would like run a block of code, and if it is not greater I would like to go to another block of code. How would I go about doing this?

Thanks for all the replies and I am very new to Kantu, so please keep it simple!

While I am here, is it possible to save the clipboard to a CSV file?


#2

For checking an element value storeText is the right command to extract it. Then you can use if/else to compare: "Target": "${rate} > 0.88",.

This example checks the USD/EURO exchange rate:

{
  "CreationDate": "2018-7-29",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=EUR",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "//*[@id=\"ucc-container\"]/span[2]/span[2]",
      "Value": ""
    },
    {
      "Command": "storeText",
      "Target": "//*[@id=\"ucc-container\"]/span[2]/span[2]",
      "Value": "rate"
    },
    {
      "Command": "echo",
      "Target": "rate=${rate}",
      "Value": ""
    },
    {
      "Command": "if",
      "Target": "${rate} > 0.88",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "so expensive!",
      "Value": "red"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "so cheap!",
      "Value": "green"
    },
    {
      "Command": "endif",
      "Target": "",
      "Value": ""
    }
  ]
}

#3

It is better to make one post for each topic… but yes, this is doable with only two lines. First use the internal variable !clipboard (gets clipboard content) and store it in !csvLine (represents the current column). Finally csvSave saves the content of !csvLine to the file.:

store | ${!clipboard}  |!csvLine
csvSave | yourFile.csv