I've been doing Google detective work for a few hours (including searching StackOverflow) for a technique to allow targeting of HTML elements produced by JavaScript in VBA.
As an example, I cannot use ie.Document.getElementById(id) on this: http://www.kisfutures.com/electronic.html?page=quote&sym=NGU12&mode=i
However, that method is quite capable of finding elements on static pages, as tested on google.com.
I've played with simply getting all the InnerText from Document.body and then parsing the file for my desired TD values, but I ran into a roadblock when trying to split two values that are on different lines. As an illustration, the following was understood by Split(..) as "2040":
20
40
From what I understand, the problem with getElementById(id) is that the website's table is generated by JavaScript after the page has loaded, and thus any elements created by that JavaScript cannot be targeted by my VBA code. Is there anyway to have my VBA code see this JavaScript-generated content?
Thank you for your help!
Edit
The VBA code being used:
Function Quote(Market, Parameter)
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.kisfutures.com/electronic.html?page=quote&sym=NGU12&mode=i"
While ie.Busy
DoEvents
Wend
Dim id As String
id = "dt1_" & Market & "_" & StrConv(Parameter, vbLowerCase)
Quote = ie.Document.getElementByID(id).InnerText
ie.Quit
End Function
Basically I try to build an HTML element ID using the column header for the Market. So if, for example the market is "NGU12" and the column header is "Open", the ID built is: "dt1_NGU12_open", which is the ID for the TD element containing the "Open" value for market NGU12.
Is there a way to have JavaScript write the necessary elements for Document.getElementById(..) before it is called?Write where? Before what is called?innerTextwill be tricky. For example, Firefox does not supportinnerText, and uses the W3C standardtextContentinstead. Whitespace will also be treated differently (e.g. You won't get line breaks with FFtextContent), and you will get thescripttag contents as well. Apparently Opera (I haven't tried it myself) hasinnerText, but it's treated astextContent. I feel the only reliable way of getting consistent content is withinnerHTML, but then you will be parsing markup, which is a whole other problem.