我正在尝试将 HTML 放入具有 id“ block ”的 HTMLElement 中。 我试过:
If webbrowser1.document.getelementbyid("block") isnot nothing then
MsgBox(webbrowser1.document.getelementbyid("block").innerHTML)
end if
但它一直抛出 NullReferenceException 并告诉我检查它是否为 null/nothing,这正是我正在做的。
那么如何检查 HTML 文档中具有特定 ID 的元素是否存在?
最佳答案
这里可能发生的是 webbrowser1.document 为 Nothing,这就是导致 NullReferenceException
被抛出的原因。
试试下面的代码
If webbrowser1.document IsNot Nothing Then
Dim element = webbrowser1.document.getelementbyid("block")
if element isNot Nothing Then
MsgBox(element.innerHTML)
End if
end if
关于html - 检查 HTMLElement 是否存在于 webbrowser 控件 (vb.net) 的 Document 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2022070/