Forum Discussion

mbcollins2's avatar
New Contributor
3 years ago

Region Checkpoint - OCR

This might be a feature request, or maybe someone can point me in the right direction.

Is there some way in keyword tests, like a Region Checkpoint, to specify an image capture on the screen,

and ONLY after you've captured the image to perform an OCR action on the image that you captured?

I can use Property checkpoints, but those require a specific xpath (choose one of these xpath options). However, with highly dynamic sites, I find that the handles I'm looking for can change and do change. So, in some instances, xpath can be unreliable--not because of TestComplete, but because of the way the web site was built.

It would be super handy to be able to select an image capture area, and then perform OCR on that image capture area. While that xpath may change, the expected information shows up in the expected place, give or take a couple of pixels up or sideways.

Is there such a feature? Can someone show me how to get there?
Or is this a feature request?

  • That was helpful. Thanks!

    So, I ended up creating a function that I could parameterize by calling the Run Script Routine in my keyword test.
    I can use this over and over again for both web pages and PDFs.

    The only inconvenience with this is getting the correct parameters--clientX, clientY, width, height--into my Run Script Routine.
    I end up using the Post Screen Shot keyword test to select the relevant area.

    Then I read those values from the Post Screenshot keyword test, and type them into my parameterized routine.

    I think this is more reliable (less prone to false errors) than calling a Region Checkpoint. Often with Region Checkpoint, the text in question can be an exact match, but the test returns false due to a slight shift in pixels horizontally and/or vertically.

    This is also a good option when I'm working on highly dynamic web sites and the xpath may not be reliable from page view to page view--especially around modal popups.

    I'm wondering if TestComplete will ever create a keyword test like this?
    I'd like to drop a keyword test in place, select the screen area in question (not xpath), and then OCR the text just from that region and check for the desired text.

    Do you think TestComplete will ever make this kind of feature?



    function verify_text_present(clientX, clientY, width, height, textToFind) {

    w = Sys.Desktop.ActiveWindow().Picture(clientX, clientY, width, height);
    var recognizedText = OCR.Recognize(w);

    if (aqString.Find(recognizedText.FullText, textToFind, 0, false) > -1) {

    Log.Message("Found " + `"` + textToFind + `"` + "in the following text OCR extracted from the specified screen area:" + "\n\n" +recognizedText.FullText);

    return true;
    } else {

    Log.Message("Did Not Find " + `"` + textToFind + `"` + "in the following text OCR extracted from the specified screen area:" + "\n\n" +recognizedText.FullText);

    return false;


4 Replies

    • mbcollins2's avatar
      New Contributor

      thank you for the suggestion!

      I've been able to capture a portion of the browser screen, and apply OCR to that image.

      I see the OCR checktext() indicating pass or fail in my log as expected.

      However,  I am struggling with how to identify the return value so that I can log a PASS or FAIL message with details.
      CheckText doesn't appear to return anything in my script.
      I've tried leaving as it is written below, assuming checkText() returns a boolean true.
      That didn't work.

      I've also tried (checktext()  != -1)

      that also doesn't seem to work.

      Any suggestions on how I might evaluate the results of this so that I can then provide a more detailed log message?







      function Test2()


      var w;
      w = Sys.Desktop.ActiveWindow().Picture(248, 249, 942, 483);
      Regions.AddPicture(w, "aaaTest");

      StoredPict = Regions.GetPicture("aaaTest");
      if (OCR.Recognize(StoredPict).CheckText("*Google*")) {


      } else {