Forum Discussion

Ted_W_Scheafer's avatar
Ted_W_Scheafer
Occasional Visitor
11 years ago

Waiting for Frame to load.

I am currently encountering an issue from time to time in my scripts about not having permissions to access the frame.contentDocument.readyState.  It is never in the same place or in the same script.



Has anyone else ran into this issue?  If so, how did you solve for it?



Here is the code that I am executing.



Do While GetTickCount() < stopTime

    frames = page.FindAllChildren("ObjectType", "Frame", 5, True)

    If UBound(frames) >= 0 Then

      waitFrame = False

      For i = 0 To UBound(frames)

        Set frame = frames(i)

        Do While frame.ContentDocument is nothing

          aqUtils.Delay(100)

        Loop

        If frame.Exists And frame.contentDocument.readyState <> "complete" Then

          waitFrame = true

          Exit For

        End If

      Next

      If Not waitFrame Then

        Exit Do

      End If

      aqUtils.Delay(1000)

    End If

  Loop
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi Ted,



    I think that the problem is caused by the fact that VBScript does not support short-circuit evaluation of the logical expressions and always evaluates all conditions even if it is not necessary.

    So it is possible that frame.contentDocument may exist but its readyState property is not accessible yet.



    I would suggest to modify your code like this:

    instead of:

            If frame.Exists And frame.contentDocument.readyState <> "complete" Then

              waitFrame = true

              Exit For

            End If



    try this (not tested):

            If frame.Exists 

              Do While Not aqObject.IsSupported(frame.ContentDocument, "readyState")

                aqUtils.Delay(100)

              Loop



              Do While "complete" <> frame.ContentDocument.readyState

                aqUtils.Delay(100)

              Loop



              waitFrame = true

              Exit For

            End If