Manipulating the Document Model Object (DOM) Using Winform’s WebBrowser

Today I will talk about using the WebBrowser control that ships with all versions of Microsoft Visual Studio, to access the DOM of an HTML page. This control is a wrapper for the WebBrowser ActiveX control, or basically, whichever version of Internet Explorer you have installed on your machine. As a result, you can only ask it to do things depending on whatever version you have installed. At the same time, the pages will render using that version of IE, and not the latest. So, if you desire to get full advantage of this control, you should probably install the latest IE version available (or Microsoft Edge, if you are using Windows 10).

The purpose of this control is to provide your users with the ability to see Web content in your Winform or WPF applications. You can also access the WebBrowser class directly by using the System.Windows.Forms.WebBrowser class. There are times when you don’t want the user to directly interact with the WebBrowser however. What you do instead, is to provide the users with other controls, and manipulate the WebBrowser’s Document (DOM) property. For example, let’s suppose you have a registration system on your website, and you want users to register from your Winform application, but don’t want the application to have a WebBrowser, and you haven’t created APIs to do this yet. You could create a Form on your application with textboxes, and then use a WebBrowser to access your registration page, hide it, pass the Form’s data to the page by manipulating the DOM, submit the web form, and wait for a response page. Now, this is not necessarily going to be pretty, but it could be an alternative when you don’t have the resources to do it the right way.

Whatever the reason you want to use the WebBrowser may be, you could automate a lot of things taking advantage of this control (I have used it countless times, and it have saved me from a lot of headaches). So, how do we go about doing this? Well, let’s work on a little example, shall we?

Manipulating the WebBrowser’s DOM to Login to Facebook

This example is for educational purposes only. Facebook provides APIs to do things like this, and you should use them whenever you can. The same if your own site contains APIs or services you can use instead. So, do not use this example to abuse Facebook, or any other site for that matter.

1. Create a new Winform project.
2. On the default form, drag and drop a WebBrowser control. This can be found at the bottom of the “Common Controls” toolbox. The WebBrowser will cover the entire Form by default. You may change this behavior if you wish.
3. Access the Form’s Load event, and add the following line of code:

private void Form1_Load(object sender, EventArgs e)

This line is pretty self-explaining. You are asking the WebBrowser to go to the Facebook page. Now, not a lot of people use Internet Explorer, but if you do, please make sure you are logged out of Facebook before you compile and run. Otherwise, you will not see the login form.

4. We will now handle the DocumentCompleted event of the WebBrowser. This event triggers when a Document has completed loading.

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    //validate that you are in the login page
    webBrowser1.Document.GetElementById("email").InnerText = "";
    webBrowser1.Document.GetElementById("pass").InnerText = "123456";


If you run the project, you will notice that the browser will go to Facebook, and will fill up the textboxes, and submit itself. Notice that the GetElementById method works exactly like the one in JavaScript. Also, the InvokeMember method will be very useful. You can invoke/trigger other methods on HTMLElements such as click, change, etc.

You can use your imagination to take advantage of the WebBrowser control. Make sure to always use your favorite browser’s Developer Tools to access the pages DOM, and get the ID’s of the elements, or class names etc.

There are other tools you can use to access the HTML or DOM of a web document, such as HTMLAgilityPack, but that will be the topic of another entry.


  1. Cialis from canada April 13, 2018 at 1:27 am

    Cialis generico online

    Valuable data. Thanks!

  2. Online viagra April 13, 2018 at 1:29 pm

    Viagra bula

    Many thanks! Useful information!

  3. Low cost cialis 20mg April 13, 2018 at 6:35 pm

    Cialis vs viagra

    Thanks a lot. A good amount of stuff.

  4. Viagra generika April 13, 2018 at 8:26 pm

    Viagra generic

    Thanks, Excellent information.

  5. Cialis generic April 14, 2018 at 9:05 am

    Cialis 5mg

    You mentioned it well!

  6. Cialis 5mg April 14, 2018 at 7:00 pm

    Cialis 20mg

    Many thanks! I appreciate it.

  7. Viagra tablets australia April 15, 2018 at 3:06 am

    Viagra for sale

    You actually reported this really well!

  8. Generic cialis April 25, 2018 at 10:59 am

    cialis cost

    Thanks a lot! Useful information!

  9. Generic cialis May 10, 2018 at 10:13 am

    viagra or cialis

    Thanks a lot. Lots of advice.

  10. Buy cialis May 26, 2018 at 5:10 pm

    cialis 5 mg

    You actually expressed this exceptionally well!

  11. writeessay May 27, 2018 at 5:20 pm

    write essay for me

    With thanks! Great information!

  12. Cialis coupon May 27, 2018 at 5:23 pm

    generic for cialis

    Good information. Thanks.

  13. Cialis online May 30, 2018 at 7:29 pm

    viagra vs cialis

    Wonderful postings. Many thanks.

  14. Cialis for daily use August 30, 2018 at 7:36 am

    cialis tablets australia

    Whoa loads of useful facts!

  15. Google September 14, 2018 at 12:48 pm


    We like to honor numerous other world-wide-web web sites on the net, even when they aren’t linked to us, by linking to them. Underneath are some webpages really worth checking out.

  16. buy cialis pills online October 31, 2018 at 9:03 pm

    global pharmacy canada

    Many thanks, I value this.

  17. buy cialis online without prescription December 9, 2018 at 10:22 pm

    canadian online pharmacies

    Incredible a lot of excellent material.

  18. cialis without a doctor 20mg December 11, 2018 at 11:15 am

    online canadian pharmacies

    With thanks! Excellent information!

  19. canadian pharmacy meds February 12, 2019 at 6:36 pm

    canadian pharmacy online 24

    Useful content. Thanks.

  20. Viagra generico online February 14, 2019 at 4:26 pm

    Viagra manufacturer coupon

    This is nicely put. !

  21. Viagra canada February 15, 2019 at 10:21 am


    Fantastic information. Many thanks.

  22. Cialis 20 mg February 23, 2019 at 12:21 pm

    buy cialis online

    Many thanks, Quite a lot of forum posts.

  23. Viagra purchasing March 16, 2019 at 2:00 pm

    Online viagra

    Kudos! Wonderful information!

  24. vardenafil hcl 20mg tab March 18, 2019 at 10:01 am

    canada pharmacies online

    Fantastic write ups. Many thanks!

  25. Tadalafil 20 mg April 5, 2019 at 2:49 pm

    canada pharmacy online

    This is nicely put! .

  26. buy viagra online best price April 6, 2019 at 9:16 pm

    safe canadian online pharmacies

    Thanks a lot! I appreciate it!

  27. 3mc8w5wt4twyvnmtc5twmcw June 19, 2019 at 8:09 am


    […]check beneath, are some entirely unrelated internet websites to ours, nonetheless, they may be most trustworthy sources that we use[…]

  28. levitra July 15, 2019 at 1:49 pm

    canadian pharmacies

    Nicely put. Cheers.

  29. viagra tablets July 16, 2019 at 2:00 pm

    canadian pharmacy no prescription

    Thanks, Great stuff.

  30. buy viagra July 17, 2019 at 8:03 am

    canadian pharmacy online 24

    Well expressed truly! !

  31. generic viagra 100mg July 17, 2019 at 11:07 pm

    canada pharmacies online prescriptions

    You actually expressed it exceptionally well!

  32. sildenafil 100mg July 18, 2019 at 10:57 pm

    Canadian Pharmacy USA

    Thanks a lot! A good amount of forum posts!

  33. international pharmacy July 19, 2019 at 12:28 pm

    canadian viagra

    This is nicely said. !

  34. canada pharmaceuticals online July 20, 2019 at 9:12 am

    best canadian mail order pharmacies

    Good info. Cheers!

  35. pharmacy online July 21, 2019 at 6:46 pm

    highest rated canadian pharmacies

    Nicely put, Regards!

  36. canadian pharmacies July 22, 2019 at 8:36 am

    Canadian Pharmacies Shipping to USA

    Very good facts, Cheers!

  37. canadian pharmaceuticals online July 23, 2019 at 9:47 am

    canadian pharmacy no prescription

    Many thanks. Valuable information!

  38. cialis prices July 24, 2019 at 1:24 pm

    online drug store

    You said this superbly.

  39. cialis July 25, 2019 at 9:29 am

    online pharmacy canada

    This is nicely expressed. !

  40. online pharmacy July 26, 2019 at 7:05 pm

    buy viagra 25mg

    Wow loads of amazing data!

  41. canadian pharcharmy July 27, 2019 at 6:50 pm

    global pharmacy canada

    Excellent information. With thanks.

  42. viagra without a doctor prescription July 27, 2019 at 9:59 pm

    online canadian pharmacy

    Tips certainly regarded!.

  43. Google September 29, 2019 at 10:55 pm


    Just beneath, are several absolutely not related web-sites to ours, however, they are surely worth going over.

  44. amoxicillin 500 October 1, 2019 at 5:02 pm

    canadian rx world pharmacy

    Cheers! Ample data!

Leave a Comment