Programming with Blessings! C# | Episode 2 | WebBrowser Login!


8 June 2016


Step 1 - Lets Start
Ok So first thing create a new C# Windows Form Project.

Step 2 - What We Need
Next we are going to want to grab our components, we will need:

  1. 2x Textboxes
  2. 1x Button
  3. 1x WebBrowser

Place these components anywhere on the form it doesn't really matter.

Step 3 - Adjusting the WebBrowser
Now we need to change a few properties on the WebBrowser Component.

Under the Behaviors Tab change the URL to whichever website you want to login to, I will be using puush / login today
and change the visibility to false. (You don't have to do this but it's recommended that you do if you're releasing the program so users won't see the browser)
(I would probably keep it set to true whilst your in the creation and debugging process)

Step 4 - The Button Code
First off re-size the browser to a smaller size put it somewhere on the form that won't annoy you.

Next we are going to double click our button to enter the code file.

Once inside we are going to want to type this code in.
The first two lines are going to input our username and password which we will have linked to our textboxes, the third line will click the login button.

Now if the elements we are grabbing don't have the value attribute we will use this code

Step 5 - Getting the Element ID's
Okay next we need to grab the element id's of the Username box, Password box, and Login button for the website we are logging in to, and for this we will need a browser with inspect element I will be using Google Chrome.

So navigate to your websites login page and right click inspect element on the username box

Now in the Elements tab it should place you straight into the username boxes div tag and what we are looking for here is the ID or if it's not there the name

Now repeat the same process for the password box

once you have both ID's we are going to need to put them in the GetElementById string field Username in the first field password in the second
like so

Now we just need to grab the button we do the exact same as before and get the ID or name if there is no ID.

Now place the ID in the GetElementById string field and we are good to go.

Now if your button has no ID this is where the extra method we added comes in find another attribute such as

once you have this attribute and it's value we can set them as the variables for the method

About Us

Forum Authority is a general discussion forum. We currently have a variety of categories to choose from, where you can participate in discussions. We also have many features such as a powerful credits & awards system, custom upgrades, plugins + more! Here you have the opportunity to meet new people, learn something new, find unique resources & tutorials, win contests & prizes, receive freebies and be given advice or help.