Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if HTMLElement exists in Document in webbrowser control (vb.net)

I am trying to get the HTML inside a HTMLElement which has an id "block". I have tried:

If webbrowser1.document.getelementbyid("block") isnot nothing then
  MsgBox(webbrowser1.document.getelementbyid("block").innerHTML)
end if

But it keep throwing a NullReferenceException and tells me to check if it null/nothing which is what I'm doing.

So how do I check if an element in a HTMLdocument with a certain ID exists?

like image 366
Jonathan. Avatar asked Dec 03 '25 03:12

Jonathan.


1 Answers

What's likely happening here is that webbrowser1.document is Nothing and that is what's causing the NullReferenceException to be thrown.

Try the following code

If webbrowser1.document IsNot Nothing Then
  Dim element = webbrowser1.document.getelementbyid("block")
  if element isNot Nothing Then
    MsgBox(element.innerHTML)
  End if
end if
like image 200
JaredPar Avatar answered Dec 04 '25 21:12

JaredPar