Automating Facebook Login using WebBrowser Control in C#

No.of Views15977
Bookmarked0 times
By  amalhashim   On  30 Sep 2010 10:09:59
Tag : CSharp , Utilities
Automating Facebook Login using WebBrowser Control in C#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at



In this article, i have to show you all, how to do the auto login to facebook using C#.

Create a new windows forms application project.

Add two button and place the web browser control as shown below. Rename the button as “btnShowPage” and “btnLogin”. 

Image Loading

On form load event use the following code

private void Form1_Load(object sender, EventArgs e)
    btnLogin.Enabled = false;

 Now on button btnShowPage use the following code

private void btnShowPage_Click(object sender, EventArgs e)
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{string s = webBrowser1.DocumentText;
    btnLogin.Enabled = true;

 On btnLogin click event use the following code

private void btnLogin_Click(object sender, EventArgs e)
    HtmlElement ele = webBrowser1.Document.GetElementById("email");if (ele != null)
        ele.InnerText = "";

    ele = webBrowser1.Document.GetElementById("pass");if (ele != null)
        ele.InnerText = "password";

    ele = webBrowser1.Document.GetElementById("Login");if (ele != null)

 that's all.enjoy.

Sign Up to vote for this article
About Author
Occupation-Software Engineer
Company-Aditi Technologies
Member Type-Senior
Location-Not Provided
Joined date-07 Jun 2009
Home Page-
Blog Page-
I have done my masters in Computer Applications and graduation in Computer Science. I have great passion in working with Microsoft tool and technologies. I am also a Microsoft Most Valuable Professional. Personally my objective is to design/develop applications which eases user experience and performs better in long run.
Other popularSectionarticles
By:CarlosDate Of Posted:6/2/2014 1:48:25 PM
Thanks a looooot
By:ducDate Of Posted:4/5/2012 9:06:23 AM
Out facebook
How auto out facebook ,
By:aminDate Of Posted:3/28/2012 1:28:41 AM
thank you very very much.....!! :x :x :x
By:Date Of Posted:3/6/2011 6:27:55 AM
Login goes wrong
I am trying to do the exact same thing, but after I perform the login click, it takes me to an error page. I looked at the sent information(including post data) and everything is as it should be.
By:BinaryBrotherDate Of Posted:11/21/2010 12:04:19 AM
This is really useful... You should post in other places, it took me a while to find this PERFECT example. Thanks. :)
By:Sohail AhmedDate Of Posted:10/9/2010 5:55:58 AM
Automating Facebook Login using WebBrowser Control in C#
it was an excellent tutorial thank you any one who post it.
Leave a Reply
Display Name:
(not display in page for the security purphase)
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top