views:

789

answers:

2

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?

+2  A: 

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
JaredPar
No it is definately the Element I tried that and it didn't throw the exception but when going line through I saw the document was a document and the element was nothing so I used this code:` Dim element = webbrowser1.document.getelementbyid("block")`` if element isNot Nothing Then`` MsgBox(element.innerHTML)`` End if`Which is exactly what I put in my question just a little longer?
Jonathan
A: 

I could also be that the element you get does not support InnerHtml or does not have InnerHtml

Jeroen