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 7972393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:51:10+00:00 2026-06-04T07:51:10+00:00

Windows Form Application – Manipulating input-elements in WinForm WebBrowser Although I am familiar with

  • 0

Windows Form Application – Manipulating input-elements in WinForm WebBrowser

Although I am familiar with HttpWebResponse/HttpWebRequest to login to a website, I was trying it now via using the mshtml library and found some weird behavior and I would like to see if someone else might be able to help me out here..

I have an HTML login page with a java backend with a Username field, a Password field and a Button.

The logic is very basic, I have a built a winform app with a built in webbrowser.
At the Document_Completed event I use the following code to enter my settings and to click the button.

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    if (webBrowser.Url.ToString() == @"MyWebPage/signin")            
    {
        HTMLDocument hdc = new HTMLDocumentClass();
        hdc = (HTMLDocument)webBrowser.Document.DomDocument;

        IHTMLElement elb = hdc.getElementById("login_button");
        IHTMLInputElement elu = (IHTMLInputElement)hdc.getElementById("username");
        IHTMLInputElement elp = (IHTMLInputElement)hdc.getElementById("password");

        try
        {
            elu.value = "MyID";
            elp.value = "MyPwd";
            elb.click();
        }
        catch { }
    }
}

Apart for this code being very quick and without error handling, it should do the trick and it does, partially..

There are two scenario’s:

  • I launch the tool, it loads the webpage.

    • The tool populates the UserID field and the Password field correctly
    • The tool fails to click the button
  • I click the button manually, I am logged in, I click logout, I am back at login page

    • I immediatly logged in again, the tool enters the information
    • The tool immediatly clicks the button as well.

Is there anyone who might be able to explain me why this happens and how I could get around this with the current setup (hence not using HttpWebRequest). I don’t see the difference between loading the page at startup or being redirected after logout, but apparently there is a difference in there or I am doing something wrong.

Any feedback on this matter is very much appreciated.

Thanks,
Kevin

EDIT:

I added a Button to my Windows Form that bas the same backend Code as below in order to click the button on the webpage, this works perfectly.

I triggered clicking this button in the webBrowser_Completed event but it doesn’t work.
For some reason, everything I add to the webBrowser_DocumentCompleted event does not allow me to trigger the click event for the button in my WebBrowser control. Once that entire event has completed, if I then try to trigger it it works but I would like to automate this.. Any advice?

  • 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-04T07:51:11+00:00Added an answer on June 4, 2026 at 7:51 am

    This might be a long shot and not the most elegant workaround but how about letting a backgroundworker run for a second in your DocumentCompleted event that then triggers the button that you clicked from it’s seperate thread. This might just get this automated.
    As this will run from a different thread, keep in mind that you might have to invoke certain controls so this might be another downside to this workaround..

    If this doesn’t work then, as Regfor previously suggested, Watin.org can help you out.

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

Sidebar

Related Questions

I've a windows form application where it ask the user to login before loading
There is a windows form application which i am trying to convert to wpf
I m working on windows form application. I need to show amount in words
I have a C# Windows Form application that contains a menu with this event:
I have a C# windows form application (Actually it is a IE toolbar application),
I have a Windows Form application. Version 1 of my app has been released
Im using c# .net windows form application. i have a SQL database with 5
I have a Windows form application that's consuming web services over https and is
Im using c# .net windows form application. I have many databases created using sql
Im using c# .net windows form application. I have loaded names of all the

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.