在 VBA 中,如果我使用 getElementByID("id_name") 并且 id 不存在,则该函数不返回任何内容,而是返回 null。这让我不知道 DOM 是否尚未渲染元素,或者该元素是否真的不存在。似乎规范要求返回 NULL 并且 NULL 不等于 Nothing。所以我的问题是这个 DOM 函数是否返回 NULL、Nothing 或者它是否依赖于我缺少的东西?谢谢
片段
If Not IsNull(p_IE.Document.getElementById(MAIN_SR_CONTAINER)) Then
' If I do not receive NULL I want to assume that I can grab the element.
' Still, I verify that the element is not Nothing
' problem is that NULL <> Nothing so if the element does not exist my code loops for eternity
' I do look at the readystate of the p_IE object and wait till it = 4
' But the elements may be being created by embedded javascript on the fly
Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
Do While elMainSRContainer Is Nothing
Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
Loop
:
:
Else
' bail
End If