Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:53:00+00:00 2026-06-08T10:53:00+00:00

Alright so I am new here so I apologize in advance if I post

  • 0

Alright so I am new here so I apologize in advance if I post incorrectly or am a little vague. My problem is that I run into a NullReferenceException when I try to run my code but while debugging and hovering my mouse over the problematic variable, I do indeed see the value of the variable.

Here is the VB code that I am working with:

Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
    status.Text = "Connecting...."

    WebBrowser2.Navigate("http://*****.com/?op=login")
    WebBrowser2.Document.GetElementById("loginUsername").InnerText = username.Text
    WebBrowser2.Document.GetElementById("loginPassword").InnerText = password.Text
    WebBrowser2.Document.GetElementById("loginSubmit").InvokeMember("click")

End Sub

Here is the snapshot of what is going on:

screenshot

———— EDIT : SOLUTION ——————-

    WebBrowser2.Url = New Uri("http://*****.com/?op=login")
    WaitForPageLoad() ' <---------- ADDED NEW FUNCTION TO WAIT FOR PAGE LOAD

    WebBrowser2.Document.GetElementById("loginUsername").InnerText = username.Text
    WebBrowser2.Document.GetElementById("loginPassword").InnerText = password.Text
    WebBrowser2.Document.GetElementById("loginSubmit").InvokeMember("click")

    status.Text = "Completed"

So I created a new function (credits go to BGM in How to wait until WebBrowser is completely loaded in VB.NET?) called WaitForPageLoad() which essentially loops through a check for the page to be ready and then once it is, is kills the handler so the login is successful and the page does not loop. Here is the WaitForPageLoad():

Private Property pageready As Boolean = False

Private Sub WaitForPageLoad()
    AddHandler WebBrowser2.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
    While Not pageready
        Application.DoEvents()
    End While
    pageready = False
End Sub

Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
    If WebBrowser2.ReadyState = WebBrowserReadyState.Complete Then
        pageready = True
        RemoveHandler WebBrowser2.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:53:04+00:00Added an answer on June 8, 2026 at 10:53 am

    WebBrowser2.Navigate takes some time to load the document, but is asynchronous. That means that the next code gets executed before the document finishes loading.

    Consequently, in the next line, GetElementById cannot yet find the target element and returns Nothing. To prevent this, you cannot execute code after calling Navigate – instead, you need to create an event handler for the event that is fired once the document finished loading, and execute the code there. – This is the DocumentCompleted event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, so here's the portion of my code that is giving me a problem.
I'm new to objective-c and ios, but I'm coming along alright. Now I've run
Alright, here's my dillema. I am making a simple application with Qt Creator that
Alright, so heres my problem: I have an application I am working with that
Alright here's the situation, I have an application written in the Zend_Framework, that is
Alright, here we go. I have a cocos2d app, and there are targets that
Alright, I have a strange one here. We currently have a tools application that
Alright, I understand that this problem has been asked a lot of times at
Alright so here is the deal. I am trying to make a application that's
Alright, possible a naive question here. I have a service that needs to log

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.