Check if HTMLElement exists in the document in the webbrowser control (vb.net)

I am trying to get HTML inside an HTMLElement that has an id of "block". I tried:

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

But he continues to throw a NullReferenceException and tells me to check if it is null / nothing, which I am doing.

So, how to check if an element exists in an HTML document with a specific identifier?

+3
source share
1 answer

What can happen is that webbrowser1.document is Nothing, and that is what throws a NullReferenceException .

Try using 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 
+5
source

Source: https://habr.com/ru/post/1242834/


All Articles