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

  • Home
  • SEARCH
  • 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 8614165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:03:29+00:00 2026-06-12T05:03:29+00:00

My problem is simple yet i cannot figure out why it’s not working inside

  • 0

My problem is simple yet i cannot figure out why it’s not working inside of if/loop. Here are some examples:

Working one:

private void button1_Click(object sender, EventArgs e)
{
    webBrowser1.Document.GetElementById("login").SetAttribute("value", "something");
    webBrowser1.Document.GetElementById("password").SetAttribute("value", "something");
}

Non working one:

if (webBrowser1.IsBusy == false)
{
    webBrowser1.Document.GetElementById("login").SetAttribute("value", "something");
    webBrowser1.Document.GetElementById("password").SetAttribute("value", "something");
}

No matter what the “if” statement is, it’s not working. Also tried with “for”, also tried to get it out of the loop of “for”, i still get this error: “Object reference not set to an instance of an object.”

  • 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-12T05:03:30+00:00Added an answer on June 12, 2026 at 5:03 am

    I’m taking a guess here because of the limited information.

    I think you are trying to modify the page right after setting the Url property. The webpage will not yet be loaded then so the controls you are getting are not available yet.

    Try adding the code to the DocumentCompleted event of the WebBrowser. This event will be triggered right after the document is fully loaded and the elements will be available then.

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      var loginControl = webBrowser1.Document.GetElementById("login");
      var passwordControl = webBrowser1.Document.GetElementById("password");
    
      if (loginControl != null)
        loginControl.SetAttribute("value", "something");
    
      if (passwordControl != null)
        passwordControl.SetAttribute("value", "something");
    }
    

    more: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx

    Update

    Your assumption about IsBusy is not completely correct. It starts out false when nothing is loaded. settings the Url property will not immediately set it to true.

    For an alternative you requested you could use the ReadyState property that will have the value of WebBrowserReadyState.Complete when loading is done. you could use the following example. Although i personally don’t like it as there is the risk of endless loop when the page can’t load for some reason. I would advise to use the DocumentCompleted if possible and i modified that example to correctly handle non-login pages as well.

    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
      Thread.Sleep(0);
      Application.DoEvents();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really simple problem, but I cannot figure out how to script
Simple problem that I can't figure out... How can I print a '%' character
I search for a working solution for a rather simple problem, but could not
My problem is very simple, yet I feel lost while looking at it ...
The problem I am having is probably very simple to solve, yet it seems
My problem is a simple on, but I haven't found a solution yet. I
I'm sure this is dead simple, but I can't seem to figure it out.
I am very new to PhoneGap yet have not been able to get some
On the face of it, this seems a very simple problem but for some
I have a relatively simple problem, which I cannot tackle without a lot of

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.