html - 检查 HTMLElement 是否存在于 webbrowser 控件 (vb.net) 的 Document 中

标签 html .net vb.net browser

我正在尝试将 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/

相关文章:

html - 无法显示正文背景图片或标题图片

javascript - 使用 jquery 或 javascript 将表单值插入到 SQL 查询中

vb.net - 我如何使用 Exchange 网络服务获取真实的电子邮件地址?

c# - 获取 NotifyIcon 的所有者表单?

c# - 如何在 VBCodeProvider 中启用隐式续行?

html - 如何使用 CLI 在 Windows 操作系统中将 node.js 6.x 更新到 8.x

php - 提交表单方法get时保留$_GET ['p']

html - 如何使按钮大小相同并在页面上居中?

c# - .Net 无法创建 SSL/TLS 安全通道

c# - 运行命令提示符 .exe 应用程序时,将超时定义为 C# WPF 应用程序中的特定行