GetelementsByTagName seems to not work properly

2019-07-29 11:08发布

问题:

this question sounds stupid but how come when I use the function GetElementsByTagname("frame") , it only returns 3 as a length and not 5 as I expected ?

Here is the HTML of the webpage where I counted 5 times the apparition of the tagname "frame" but when I ask for the length in VBA I get 3...

My observations :

1) You can see that 3 is the number of main frames (top_navigation, contentframe, dummyframe)

2) If I try to access to one of the mainframes via getelementbyname, it works but if I try to access on the the subframes of contentframe ( leftnavigation or postfachcontent) it doesn't work ( 0 item detected)

Here is my code :

Dim Frame As IHTMLElementCollection
  Set Frame = IEDoc.getElementsByName("contentframe") ' this works and returns 1 item
   MsgBox Frame.Length
   Set Frame = IEDoc.getElementsByName("postfachcontent")
  MsgBox Frame.Length ' this returns 0 item


Dim Collection As IHTMLElementCollection

Set Collection = IEDoc.getElementsByTagName("frame")
MsgBox Collection.Length ' this returns 3 and I expected 5...

回答1:

Only 3 frames are on that page, the rest are inside an embedded html frame which getElementsByTagName cannot access as it is a different DOM tree.