Reputation: 35
The problem happens only when used getElementsByClassName
Dim HTTP As New MSXML2.XMLHTTP60
HTTP.open "POST", strWWW, False
HTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
HTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
HTTP.send ("obj=" & strID)
Dim HTML As New MSHTML.HTMLDocument
HTML.body.innerHTML = HTTP.responseText
Dim eleCol As MSHTML.IHTMLElementCollection
Set eleCol = HTML.getElementsByClassName("listEvent sro") '<-- The problem is happening here.
The tests are being done on Windows 8.1 and Windows XP
Windows 8.1
While in IDE everything works normally, but when compiled simply the error appears:
mshtml.dll 11.00.9600.18860
mshtml.tlb 11.0.9600.16518
The method exists, but now why it works while in IDE, but not when compiled?
Windows XP
Not even in the IDE worked, presenting the following error message:
mshtml.dll 8.0.6001.23588
mshtml.tlb 8.0.6001.18702 (old version and there is no getElementsByClassName)
mshtml.tlb 11.0.9600.16518 (using this version but it does not work)
What am I doing wrong?
Upvotes: 1
Views: 745
Reputation: 35
Your tip solved the problem.
The list of nodes I used...
Dim eleMen As MSHTML.IHTMLElement
For Each eleMen In eleCol
debug.print eleMen.innerText
Next eleMen
... and it worked perfectly, the same way when not used
HTML.getElementsByClassName
How much do I use getElementsByTagName
also works normally, only
getElementsByClassName
that is displaying this error in the executable,
and not in the IDE.
Is it a bug in MSHTML?
Another detail is that this worked without problems too ...
Set eleCol = HTML.querySelectorAll(".listEvent.sro").Item(0).getElementsByTagName("td")
... returned all the nodes I need.
Thank you very much!
Upvotes: 0
Reputation: 84465
Try the following workaround which uses css selector syntax to select by class. With modern browsers it is a faster method for matching on elements. It may work.
Dim eleCol As Object
Set eleCol = HTML.querySelectorAll(".listEvent.sro")
Also, test whether you can remove the compound class usage and have a single class e.g.
Set eleCol = HTML.querySelectorAll(".listEvent")
You use a For Loop
from 0
to .Length -1
over the returned nodeList
.
Upvotes: 2