"If" condition is not working as expected for below mentioned case

Firstly, I stored text of an image through OCRExtract and store it in a variable “title” and Stored another text “shift” in another variable “actresult” and tried to verify the two results using if conditions. But it is not working as expected.

Attaching JSON Source code and Logs for your reference:

{
“Name”: “ifelse”,
“CreationDate”: “2023-5-22”,
“Commands”: [
{
“Command”: “OCRExtract”,
“Target”: “shft.png”,
“Value”: “title”,
“Description”: “”
},
{
“Command”: “comment”,
“Target”: “pause // 3000”,
“Value”: “title”,
“Description”: “”
},
{
“Command”: “store”,
“Target”: “${title}”,
“Value”: “title”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${title}”,
“Value”: “green”,
“Description”: “”
},
{
“Command”: “store”,
“Target”: “shift”,
“Value”: “actresult”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${actresult}”,
“Value”: “green”,
“Description”: “”
},
{
“Command”: “if”,
“Target”: “${title}==${actresult}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “Pass”,
“Value”: “green”,
“Description”: “”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “Failed”,
“Value”: “red”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}
]
}
Logs:

  • info]Executing: | OCRExtract | shft.png | title |

  • [info]OCR (eng) started (1.0 KB)

  • [info]OCR result received (0.6s from endpoint 3)

  • [info]Executing: | comment | pause // 3000 | title |

  • [info]Executing: | store | ${title} | title |

  • [info]Executing: | echo | ${title} | green |

  • [echo]shift

  • [info]Executing: | store | shift | actresult |

  • [info]Executing: | echo | ${actresult} | green |

  • [echo]shift

  • [info]Executing: | if | ${title}==${actresult} | |

  • [info]Executing: | echo | Failed | red |

  • [echo]Failed

  • [info]Executing: | end | | |

  • [info]Macro completed (Runtime 6.52s)

OCR results often contain additional spaces or line feeds. So the best solution is to

  1. Remove characters from string

  2. OR: Do a substring search instead of a direct “==” comparison.

1 Like