Solved

Automatically log into a website in webbrowser component

Posted on 2010-08-22
7
548 Views
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();">
<fieldset>
<legend>Login</legend>
<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>
<div class="field-row">
<label for="password">Password</label>
<input type="password" class="field" name="password" id="password" maxlength="16" tabindex="2" />
</div>
<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>
<div class="field-row">
<p><a href="public.php?mode=forgot" tabindex="4">I forgot my username or password</a></p>
</div>
</fieldset>
</form>
0
Comment
Question by:Oli999
[X]
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
7 Comments
 
LVL 9

Expert Comment

by:Snarfles
ID: 33494895
Is this your own site or someone elses? and how are you opening it?
0
 
LVL 5

Expert Comment

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

and that will do it for you.

details

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!
0
 
LVL 2

Author Comment

by:Oli999
ID: 33497276
it's someone else's site and I'm just using webbrowser1.navigate to open it
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 9

Expert Comment

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

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497683
0
 
LVL 9

Expert Comment

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

Accepted Solution

by:
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
                        element.InvokeMember("click")
                    End If
                End If
            Next
        End If

Open in new window

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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