Forum Discussion

MW_Didata's avatar
MW_Didata
Regular Contributor
24 days ago
Solved

Refine area to solve OCR.Recognize found 2 object

For one of my tests I need to select the right week in an agenda object.

While reading the docs https://support.smartbear.com/testcomplete/docs/reference/program-objects/ocrtextdocument/blockbytext.html

You can set different SelectionPreferences to make sure you select the right object.

 

 

Is there anyway to combine 2 SelectionPreferences


in my case I want it to select the spLeftmost and spTopmost.

When clicking Weeknumber 27 I get this warning in the logs

"2 blocks were found by the text '27'. The first block was returned"

 

The test still passes, but it gives a warning in the logs.

  • Hello,

    Unfortunately, this is not possible to do. Given an object, the OCR actions are only able to take in one selection preference. 

    Feel free to add this as a feature request for future considerations! Link to make the request is below:

    https://community.smartbear.com/category/testcomplete_forum/ideas/testxcompletefeaturerequests

4 Replies

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    The full OCR action is use is:

    OCR.Recognize(Object).BlockByText(weeknr, spLeftMost).Click();

  • Hello,

    Unfortunately, this is not possible to do. Given an object, the OCR actions are only able to take in one selection preference. 

    Feel free to add this as a feature request for future considerations! Link to make the request is below:

    https://community.smartbear.com/category/testcomplete_forum/ideas/testxcompletefeaturerequests

  • nastester's avatar
    nastester
    Regular Contributor

    MW_Didata​ 

    Question for you because I will be in a similar boat too soon I think.  Are you using OCR to automate that datepicker? 
    With the datepicker my web app has, I dont think I have the ability to set the date using some method or property or something so I'd have to click on it, which seems not good.  Just thinking about how I am going to do this... 

    • MW_Didata's avatar
      MW_Didata
      Regular Contributor

      Yes I did use OCR for this, in our application clikcing either weeknumber 27 will give you the right week.
      What i ended op doing to get around the "2 code blocks were found" warning is disabling the log posting for just this issue then re-enabling after the ocr action

      In the test i just use this:

        ProjectSuite.Variables.disableLog = true;


        OCR.Recognize(object).BlockByText(weeknr, spLeftMost).Click();


        ProjectSuite.Variables.disableLog = false;

      I created an eventcontroller on log warnings:

      which fires this function that disables the log post if the msg contains "2 blocks found":

      function Disable_OCR_Log(Sender, LogParams)
      {
        if (ProjectSuite.Variables.disableLog)
        {
          if (aqString.Find(LogParams.Str, "2 blocks were found by the text") != -1)
          {
            LogParams.Locked = true;
          }
          else
          {
            LogParams.Locked = false;
          }
        }
      }