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.getElementsByTagNa me(sElemen tTagName)
If UCase(oElement.Attributes( sElementAt tribute)) = UCase(sElementAttributeNam e) Then
ResultCol.Add oElement
End If
Next oElement
Else
For Each oElement In htmlDoc.getElementsByTagNa me(sElemen tTagName)
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.Docu ment, ...)
The error occurs on the first recursion call. Does anyone have an idea why this could be happening? Thanks.
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.getElementsByTagNa
If UCase(oElement.Attributes(
ResultCol.Add oElement
End If
Next oElement
Else
For Each oElement In htmlDoc.getElementsByTagNa
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
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.Docu
The error occurs on the first recursion call. Does anyone have an idea why this could be happening? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if a try to inspect this:
htmlDoc.frames.item(i).Doc ument
i can see error "Access denied", someone of you know why.
htmlDoc.frames.item(i).Doc
i can see error "Access denied", someone of you know why.
Is this true for every framed page you visit or just certain ones?
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.
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).Doc ument
or just showing any property like the documentElement.innertext
Set htmlDoc = htmlDoc.frames.item(i).Doc
or just showing any property like the documentElement.innertext
Set htmlDoc = htmlDoc.frames.item(i).Doc ument
I got that error when try to access Document property/object and if i try to inspect some properties in Inspection window.
I got that error when try to access Document property/object and if i try to inspect some properties in Inspection window.
ASKER