I’m new to Kantu and one of the things I’m trying to do with my first macro is click a certain area of the screen based on some text that is already there. I’ve stored the string in a variable (Description) and I now want to check it for a substring using an if statement. I’ve been trying several different ways to use a contains function, but I’m apparently failing to hit the right syntax.
So, what should my condition (Target:) be for the if statement if I want it to evaluate true when the variable includes the number 110?
Here is a code snippet to check that a string contains a certain substring. I copied the code from the DemoPDFTest_with_OCR macro that ships with Kantu.
Update: Since UI.Vision Version 4 and newer, the easier solution is to use executeScript command and the Javascript .includes feature to check that a string contains a certain substring (“string comparison”):
Hello, Happy New Year!
This command works like charm, but when we have a substring with some accent, like “Orange-PP”, the Macro can’t handle due “-” character and simply ignore. How can we fix this? Thanks!
{
"Name": "test3",
"CreationDate": "2023-5-11",
"Commands": [
{
"Command": "store",
"Target": "test tim meyer",
"Value": "e",
"Description": ""
},
{
"Command": "if",
"Target": "${e}.lastIndexOf(\"tim\") > -1",
"Value": "",
"Description": "the return value of .lastIndexOf() is -1 if the substring is not found in the string at all."
},
{
"Command": "echo",
"Target": "yes, it contains this string",
"Value": "blue",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}