Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Automatically log into a website in webbrowser component

Posted on 2010-08-22
Medium Priority
Last Modified: 2013-11-27
how to auto logon a site in a webbroswer component. What code will auto populate the username, password input boxes and autoclick the login button?

HTML looks like this:-

<form class="ccform" action="login.php" method="post" onsubmit="login();">
<span class="errormsg-inline"></span>
<div class="field-row">
<label for="username">Username</label>
<input type="text" class="field" name="username" id="username" maxlength="16" value="" tabindex="1" />
<div class="field-row">
<label for="password">Password</label>
<input type="password" class="field" name="password" id="password" maxlength="16" tabindex="2" />
<div class="field-row">
<input type="hidden" name="direct" id="direct" value="yes" />
<input type="hidden" name="redirect" value="" />
<input type="submit" class="button-inline" name="submit" value="Login" tabindex="3" />
<div class="field-row">
<p><a href="public.php?mode=forgot" tabindex="4">I forgot my username or password</a></p>
Question by:Oli999
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 33494895
Is this your own site or someone elses? and how are you opening it?

Expert Comment

ID: 33495040
create a POST request to the http://www.example.com/login.php

and that will do it for you.


Basically, you would need to do the following:
1. create a HttpWebRequest object and use HttpWebRequest.Method = "POST".
2. set the Post data to contain your data (username and password).
3. "Post" (i.e. execute and get the response for) the HttpWebRequest.

and you will face cookie not enabled issue, so make sure you enable it as described first line in the code below...

CookieContainer cookies = new CookieContainer();
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(site);
postRequest.CookieContainer = cookies; // note this
postRequest.Method = "POST";
postRequest.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = postRequest.GetRequestStream())
    stream.Write(buffer, 0, buffer.Length);

good luck!

Author Comment

ID: 33497276
it's someone else's site and I'm just using webbrowser1.navigate to open it
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497676
Using IWebBrowser2 is a good idea to do this task.

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497689
             If u need the complete code, plz let me know!

Accepted Solution

Oli999 earned 0 total points
ID: 33575610
Thanks all for your suggestions. Have figured this one out myself now though.

here's how I did it.
If (WebBrowser1.Document.All("username") IsNot Nothing) And (WebBrowser1.Document.All("password") IsNot Nothing) Then
            WebBrowser1.Document.All("username").SetAttribute("value", "username")
            WebBrowser1.Document.All("password").SetAttribute("value", "password")
            For Each element As HtmlElement In WebBrowser1.Document.Body.All
                If element.Name = "submit" Then
                    If element.GetAttribute("value") = "Login" Then
                    End If
                End If
        End If

Open in new window


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question