C# Auto click button and auto fill form

This tutorial will show you how to auto fill forms and click buttons in a website using the webBrowser control. When you learn to do this you can make your own web bots!


To show you how autoclick/autofill works we’ll make a simple Google AutoSearch Bot.

So lets begin…

First of all, add a webBrowser control to your form. Set its “Url” property to “www.google.com”.

Now we’ll add two methods SetText() and ClickButton(). SetText() method will automatically fill a textBox and the ClickButton() will click the submit button.

Since we are making a Google AutoSearch Bot we need to find what’s the name of the Google search textBox and the submit button. To find these, visit Google.com from your browser and view the page source.

Here’s the code for the SetText() method:

And now the code for the ClickButton() method:

Now that the main methods are added we can now tell the bot what to do :).

Declare “bool searched = false” at Class-level (i.e add it above pulic Form1() {…). We’ll use it to check whether we have already searched or not.

Add DoucmentComplete event for the webBrowser. DocumentComplete event is fired when the page is loaded completely.

Use this code:

Note: The name of the Google search textBox is “q” and the submit buttons is “btnG”.

That’s it! Run the project and watch the bot 🙂

If you have any questions don’t hesitate to post a comment.


Leave a Reply

Your email address will not be published. Required fields are marked *