Thread Contributor: Blessings
Programming with Blessings! C# | Episode 2 | WebBrowser Login!
#1
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.

[Image: 68600cadda.png]


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

[Image: 3a96251f6f.png]


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

[Image: 185030f70d.png]

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

[Image: c5b31a3019.png]


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

[Image: 5b2892d603.png]


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.

[Image: 4274013c73.png]

Now place the ID in the GetElementById string field and we are good to go.
[Image: e44370a986.png]


Now if your button has no ID this is where the extra method we added comes in find another attribute such as
[Image: 536540b4ba.png]

once you have this attribute and it's value we can set them as the variables for the method
[Image: 9652dcc178.png]



Users browsing this thread: 1 Guest(s)