OCRExtract error "Cannot read properties of null"

Hello,
I would like get text from image on webpage via OCR but the command OCRExtract always sends some error. My script can click in the image, the script can download the image to my computer but to get text from the image is not possible.
In the OCRExtract when I into Target write xpath=/html/body/div[1]/div[1]/div/main/article/div[1]/div[2]/div/div/div/figure[8]/div/div/picture/img, then macro sends “[error] Line 7: Cannot read properties of null (reading ‘imageUrl’)”. When I into Targer write screen10.png then macro sends "[error] Line 7: Error #120: visualAssert: No input image found for file name ‘screen10.png’(more info)"


Can you help me please?

Thank you very much.
Orna

OCRExtract and OCRExtractRelative take an image as input, not an xpath. But the error message is indeed very confusing.

If you want to extract text using XPath, then use the selenium command storeText or storeValue. See also web scraping with the selenium ide.

Interesting! I see that you are trying to use storeImage to download the image, and then run OCR on it using OCRExtract. This does not work yet, as currently OCRSearch and all other visual commands look only in the "Visual" tab and not in the Screenshots tab where storeImage puts the image. But I like the suggestion and added it on our todo list. So after one of the next updates, it will work :slight_smile:

What already works in using OCRExtractRelative (-> mark area to extract with green/pink boxes in image) and OCRExtractByTextRelative (->mark area to extract with an anchor word instead of image) . With this command, you can visually define the area from where to extract the text.

OCRExtract has been deprecated. Instead we have a new command called OCRExtractScreenshot. What this command does is that it it looks for input images in the “Screenshot” tab of Ui.Vision => Now you can OCR process any downloaded image or screenshot. Every image that is shown in the “Screenshot” tab can be used as input.

To clarify further:

  • OCRExtractRelative and OCRExtractByTextRelative look in the browser (or desktop, when in desktop automation mode) for the area to read text from.

  • OCRExtractScreenshot looks at images in the screenshot tab of Ui.Vision to read text from.

OCRExtractScreenshot Demo macro:

{
  "Name": "ImageTextExtract",
  "CreationDate": "2024-6-11",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ui.vision/",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "99",
      "Value": "!ocrengine",
      "Description": "Built-in OCR Engines: 99=xmodule, 98=Javascript"
    },
    {
      "Command": "storeImage",
      "Target": "xpath=//*[@id=\"logo\"]/img",
      "Value": "logo.png",
      "Description": "Save image"
    },
    {
      "Command": "OCRExtractScreenshot",
      "Target": "logo.png",
      "Value": "a",
      "Description": "Run OCR on the saved image"
    },
    {
      "Command": "echo",
      "Target": "Text in image: ${a}",
      "Value": "green",
      "Description": ""
    }
  ]
}
3 Likes