How to know if an iframe has loaded?

Hi all,

Using this command
selectFrame | index=1 | |

I’m getting this error

timeout reached when looking for frame 'index=1'

even I’ve set a validation using sourceSearch and the command counts 3 <iframe elements.

What other validations could I do, to avod the error in command selectFrame | index=1 | | ?

This is part f the macro I have.

{
  "Name": "CheckIfIframe",
  "CreationDate": "2024-12-8",
  "Commands": [
    {
      "Command": "label",
      "Target": "CheckIFrame",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "sourceSearch",
      "Target": "regex=/<iframe /i",
      "Value": "iframe",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "iframes=${iframe}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "${iframe} == 0",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "gotoLabel",
      "Target": "CheckIFrame",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectFrame",
      "Target": "index=1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectFrame",
      "Target": "index=1",
      "Value": "",
      "Description": ""
    }
  ]
}

As a simple test, if you add a longer delay before the command, e. g. PAUSE | 20000 for 20 seconds delay, does it work then?

Yes, setting a pause it seems to work, but I’d like to make it dynamically, without set too much unneeded seconds if possible.

Great, if PAUSE works that is a good first step.

For dynamic waiting inside iframes, we recommend to use local computer vision with visualAssert | ImageOfSomethingInFrame.png. This command will check every second if the image has been found. If not, it waits until the ${!timeout_wait} time has been reached.

If you prefer to wait for an image to disappear, that is also possible but a bit more complicated.

Thank you . I’ve tried and seems to work even I would prefer a solution without images since the macro will be use In more machines. But thank you.

I often use text search instead of image search these days. OCR is very robust against screen resolution changes and usually works on all machines I use it own. So if there is text inside your iframe, that will be a good alternative to the image search. I use OCRSearch for this:

In this demo I wait for the minute value to change from 37 to 38:

{
  "Name": "wait for text to appear on website",
  "CreationDate": "2024-12-10",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "98",
      "Value": "!ocrengine",
      "Description": "Javascript OCR engine"
    },
    {
      "Command": "open",
      "Target": "https://www.timeanddate.com/time/zone/uk/london",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "do",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "OCRSearch",
      "Target": "*:31:*",
      "Value": "i",
      "Description": "Test text search: Wait for the minute value to be a certain value"
    },
    {
      "Command": "echo",
      "Target": "i=${i}",
      "Value": "blue",
      "Description": "How often was the word found?"
    },
    {
      "Command": "repeatIf",
      "Target": "${i} < 1",
      "Value": "",
      "Description": "If found at least once the word is on the website"
    },
    {
      "Command": "echo",
      "Target": "TEXT FOUND i=${i}",
      "Value": "green",
      "Description": ""
    }
  ]
}
1 Like

Thank you @ulrich for your another idea. I’ll try it and hope to get a good anchor to search by OCR.

Nice demo the one you shared.

One question, OCRSearch looks for the string every second and waits the ${timeout} variable duration the same as visualAssert?

Good question. Both behave differently. That is why I had to create a loop myself in the OCR text wait macro.

  • visualAssert waits until the ${timeout_wait} value is reached (or image found).
  • OCRSearch does not wait. It makes one text search and reports the number of occurrences found.
1 Like