GetelementsByTagName seems to not work properly

ぃ、小莉子 提交于 2019-12-11 05:18:22

问题


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.



来源:https://stackoverflow.com/questions/40505114/getelementsbytagname-seems-to-not-work-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!