Link to home
Start Free TrialLog in
Avatar of vt45
vt45

asked on

Automation Error in recursive function

<----------Begin Code----->

Public Function GetHTMLElements(ByVal htmlDoc As Object, ByRef ResultCol As Collection, Optional sElementTagName As String, Optional sElementAttribute As String, Optional sElementAttributeName As String) As Boolean
Dim oElement As HTMLHtmlElement
Dim i As Integer
If ResultCol Is Nothing Then Set ResultCol = New Collection

If sElementTagName <> "" Then
    If sElementAttribute <> "" Then
        For Each oElement In htmlDoc.getElementsByTagName(sElementTagName)
            If UCase(oElement.Attributes(sElementAttribute)) = UCase(sElementAttributeName) Then
                ResultCol.Add oElement
            End If
        Next oElement
    Else
        For Each oElement In htmlDoc.getElementsByTagName(sElementTagName)
            ResultCol.Add oElement
        Next oElement
    End If
Else
    For Each oElement In htmlDoc.All
        ResultCol.Add oElement
    Next oElement
End If

If htmlDoc.frames.length > 0 Then
    For i = 0 To htmlDoc.frames.length - 1
        ***GetHTMLElements htmlDoc.frames(i).Document, ResultCol, sElementTagName, sElementAttribute, sElementAttributeName
    Next i
End If
If ResultCol.Count > 0 Then
    GetHTMLElements = True
Else
    GetHTMLElements = False
End If

End Function

<------------End Code------->

*** I get this error on the recursive call: "Method 'frames' of object 'DispHTMLDocument' failed"

I'm passing in and object like this:
Dim IEobj as SHDocVw.InternetExplorer

GetHtmlElements(IEobj.Document, ...)

The error occurs on the first recursion call.  Does anyone have an idea why this could be happening?  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vt45
vt45

ASKER

Doh!  Thanks.
Avatar of Richie_Simonetti
if a try to inspect this:
htmlDoc.frames.item(i).Document
i can see error "Access denied", someone of you know why.
Is this true for every framed page you visit or just certain ones?
Avatar of vt45

ASKER

I've noticed that before too Richie.  It always seemed to be the "utility" frame the website designers set aside to store thier own information.  I guess they can make it inaccessable, but I'm not sure how.  In my case it was always the first frame in the loop, so instead of "For i = 0 To htmlDoc.frames.length - 1", i did "For i = 1 To htmlDoc.frames.length - 1".
For every, that's it!
vt45, i did in same way (-1)!
Every frame is reached but for most properties, they have "Access denied".
I did a try with samples pages created by myself just to do a test, i mean, a page with frameset stuff and two more html with some stupid things inside.
You get access denied regardless of how you try and use it?  e.g.,


Set htmlDoc = htmlDoc.frames.item(i).Document

or just showing any property like the documentElement.innertext
Set htmlDoc = htmlDoc.frames.item(i).Document

I got that error when try to access Document property/object and if i try to inspect some properties in Inspection window.