0

I start to make a new application to detect all html elements on a webpage in this example i use yahoo

But i get null exception this is the error

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=autoclic
StackTrace:
   at autoclic.Form1.Button1_Click(Object sender, EventArgs e) in 
c:\users\monchique discovery\documents\visual studio 
2012\Projects\autoclic\autoclic\Form1.vb:line 7
I can not figure out how to solve this null exception 

this is my code

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.WebBrowser1.Navigate(New Uri("http://www.yahoo.com"))

    Me.ListBox1.Items.Add("Type" & "-->" & "Name")
    For Each element As HtmlElement In Me.WebBrowser1.document.All
        Me.ListBox1.Items.Add(element.TagName() & "-->" & element.Id)
    Next
    If Me.WebBrowser1.Document.All Is Nothing Then
        Return

    End If
End Sub
End Class
  • 1
    Possible duplicate of [How to wait until WebBrowser is completely loaded in VB.NET?](https://stackoverflow.com/questions/3275515/how-to-wait-until-webbrowser-is-completely-loaded-in-vb-net) – Andrew Morton Jun 29 '17 at 18:12
  • @AndrewMorton Hi hello, tank you for the replay. – Silvia Fonseca Jun 29 '17 at 18:15
  • @AndrewMorton But can you please bee more clarified on it i have check the post but they not speak about that exception – Silvia Fonseca Jun 29 '17 at 18:16
  • 1
    It takes a little time for the web page to load and be processed. You are not giving any time for that processing to happen so `WebBrowser1.Document.All` is `Nothing`. – Andrew Morton Jun 29 '17 at 18:20

0 Answers0