Using OCRextractrelative to extract text from a website

:grinning: :star_struck: :star_struck:I am going to use OCRextractrelative to extract text from a website. As you can see in the website photo, the text “包裝規格” is fixed, while “24x430亳升” is variable.


That’s why I am using “包裝規格” as the anchor image and “24x430亳升” as the click area to extract the text “24x430亳升”.

However, I’m encountering an error that says “[error] Line 10: No tab with id: 933887000.”

Would like to have your help to resolve this issue

You can use a simple storetext to store the text, it works with minimized browser window and is fast

There is no good reason to want to use OCRextractrelative it has only drawbacks and limitations

Buddy, it is because the location of the “包裝規格” would be vary from case by case, thats why i am trying to use the OCR technology

It looks like a public website. Can you post a link to it? Then I could test it.

Dear Sir,

thank you very much, yes, i am new to Ui vision, it is the specific page about the distill water:
https://www.hktvmall.com/hktv/zh/main/10號店/s/H8260001/超級巿場/超級市場/飲品-即沖飲品/水/屈臣氏-蒸餾水原箱-430亳升-新舊包裝隨機發送/p/H8260001_S_50000245

which come from the page:
https://www.hktvmall.com/hktv/zh/search_a?keyword=屈臣氏蒸餾水

Hi I created a macro with an anchor xpath that detects the text you requested based on an anchor in the page. I used a special type of xpath that ui vision doesn’t register and they are quite complex to use but they allow you to find elements with dynamic anchors as well. I added a Mouseover to show on screen that it detects the text you requested, then extracts it from the page

This xpath search the text “包裝規格” and after search this element “productPackingSpec” and store it have the same function of OCRextractrelative but works better, without limitations

Macro code

{
“Name”: “AAAA”,
“CreationDate”: “2023-6-9”,
“Commands”: [
{
“Command”: “bringBrowserToForeground”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “mouseOver”,
“Target”: “xpath=(//td[text()=‘包裝規格’]/parent::tr[@class=‘productPackingSpec’]//td )[2]”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “1000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “storeText”,
“Target”: “xpath=(//td[text()=‘包裝規格’]/parent::tr[@class=‘productPackingSpec’]//td )[2]”,
“Value”: “Value”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${Value}”,
“Value”: “#shownotification”,
“Description”: “”
}
]
}

Log

[status]

Playing macro AAAA

[info]

Executing:  | bringBrowserToForeground |  |  | 

[info]

Executing:  | mouseOver | xpath=(//td[text()='包裝規格']/parent::tr[@class='productPackingSpec']//td )[2] |  | 

[info]

Executing:  | pause | 1000 |  | 

[info]

Executing:  | storeText | xpath=(//td[text()='包裝規格']/parent::tr[@class='productPackingSpec']//td )[2] | Value | 

[info]

Executing:  | echo | ${Value} | #shownotification | 

[echo]

24x430亳升

[info]

Macro completed (Runtime 3.01s)
1 Like

it seems not work for me buddy,

log:

  • [status]

Playing macro AAAA

  • [info]

Executing: | bringBrowserToForeground | | |

  • [info]

Executing: | mouseOver | xpath=(//td[text()=‘包裝規格’]/parent::tr[@class=‘productPackingSpec’]//td )[2] | |

  • [warning]

Line 2: Element found with secondary locator “xpath=//td[2]”. To use it by default, update the target field to use it as primary locator.

  • [info]

Executing: | pause | 1000 | |

  • [info]

Executing: | storeText | xpath=(//td[text()=‘包裝規格’]/parent::tr[@class=‘productPackingSpec’]//td )[2] | value |

  • [error][ignored]

Line 4: timeout reached when looking for element ‘xpath=(//td[text()=‘包裝規格’]/parent::tr[@class=‘productPackingSpec’]//td )[2]’

  • [info]

Macro completed (Runtime 22.41s)

Actually, the value want to be extracted is always next to text:包裝規格, is that any method we can leveraging this design?

I changed xpath with anchor, it is possible that the page changes, with ui vision and Firefox it works.
I am also attaching an image where you see the notification that has extracted the value.
There are many xpaths to detect the same element so it may happen that you have to try different xpaths before finding the best one and that does not change

I use ui vision 6.2.6 for firefox, i do not use Chrome but i think that working in Google Chrome too


{
  "Name": "AAAA",
  "CreationDate": "2023-6-9",
  "Commands": [
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "mouseOver",
      "Target": "xpath=//td[text()='包裝規格']/following-sibling::td",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "pause",
      "Target": "1000",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeText",
      "Target": "xpath=//td[text()='包裝規格']/following-sibling::td",
      "Value": "Value",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${Value}",
      "Value": "#shownotification",
      "Description": ""
    }
  ]
}

Log
[status]

Playing macro AAAA

[info]

Executing:  | bringBrowserToForeground |  |  | 

[info]

Executing:  | mouseOver | xpath=//td[text()='包裝規格']/following-sibling::td |  | 

[info]

Executing:  | pause | 1000 |  | 

[info]

Executing:  | storeText | xpath=//td[text()='包裝規格']/following-sibling::td | Value | 

[info]

Executing:  | echo | ${Value} | #shownotification | 

[echo]

24x430亳升

[info]

Macro completed (Runtime 3.07s)

Image

It works well when I use Firefox. Thank you for your help.

1 Like

Just a follow-up question: What should I do if the 包裝規格 is not on the web page? How can I add a mechanism to bypass the error that occurs when the 包裝規格 is not found?

There are many solutions to solve the element not found problem, for example try clicking it or use the MouseOver command if it does not find it (statusOK == false) with an IF + GOTOLABEL command you can send the macro to the end of the loop but there are many solutions it depends on the ui vision commands you know

Here some examples
https://ui.vision/rpa/docs/selenium-ide/if