Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Document.getElementByID returning NULL
Message
From
21/11/2018 15:01:36
 
 
To
21/11/2018 14:42:14
General information
Forum:
Visual FoxPro
Category:
Internet applications
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01663647
Message ID:
01663653
Views:
40
>>Hi All,
>>
>>Even though I have done this a hundred times before, it seems to always comes back to bite me. I have HTML page with a tag with the id='count'. when I load it into the WebBrowser control and attempt to reference the tag the returned reference is NULL.
>>
>>HTML code
>>
>>... <td id='count'>123</td>
>>
>>
>>VFP code
>>
>>loID = loForm.IE.document.getElementById( "count" )
>>? loID        && displays .NULL.
>>
>>
>>I can see it in the Source View, and even in the browser Debug Console, but can not get the object reference via code in VFP. Is there a secret I am missing?
>
>If you're inside of frames, you'll need to navigate to the correct one. I got this code from Olaf Doschke on Tek-Tips. As I understand it, it would go like this:
>
>
CODE
>oIE = createobject("internetexplorer.application")
>oIE.navigate2("whatever.html")
>Do While oIE.busy Or oIE.ReadyState!=4
>   doevents
>Enddo
>* looping all oFrames items in oFrames.item(n)
>oFrames = oIE.Document.getElementsByTagName("iFrame")
>For Each oFrame in oFrames 
>  ? oFrame.contentWindow.Document
>  ? oFrame.contentWindow.Document.body.outerhtml
>  * Reference your element at: loEl = oFrame.contentWindow.document.getElementByID("content")
>  * When you get a non-null value, use this to access your content:  loEl.innerHTML
>Endfor
>
>UPDATE: Reference: https://www.tek-tips.com/viewthread.cfm?qid=1663002

Thanks for the suggestion, but I have no iFrame. After playing around a bit I discovered the element is not available until the HTML page is visible. I can now get the object reference to it, but can not change the innerText. I get an error tell me that "innerText" is not valid. It appears in the Intellisense list, but evaluates to undefined.

P.S. the 'contentWindow' reference may help. thanks.
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform