[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

logging into web sites with VB.NET

Posted on 2008-10-03
6
Medium Priority
?
413 Views
Last Modified: 2012-05-05
I have a web page I am viewing the details of, and I am using the web browser control that comes with visual studio 2008.

However, every time I go to the website I am forced to log in again. I have to reenter the username and password every time (whereas in firefox and ie, a cookie preloads these details for me).

So in two parts:

1) How can I preload this data, can I access the cookie that ie or ff have for this site?, and

2) How can I automate the log in process so that the form is submitted for me with the username and password?
0
Comment
Question by:madivad2
  • 4
  • 2
6 Comments
 
LVL 2

Author Comment

by:madivad2
ID: 22640324
I have increased the points to maximum, I didn't think this would be a hard one to answer... anybody?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22640396
>>I didn't think this would be a hard one to answer
That is where you are slightly wrong, my friend.  This is not something that gets worked with very much.  It sounds like you need to use is GetElementByID (or something else).

Example:


webBrowser1.Navigate("SomeUrl")
 
While (webBrowser1.ReadyState <> WebBrowserReadyState.Complete) 
  Application.DoEvents();
End While
 
webBrowser1.Document.GetElementById("username").InnerText = "someUsername"
webBrowser1.Document.GetElementById("password").InnerText = "somePassword"
webBrowser1.Document.GetElementById("submit1").InvokeMember("click")
 
While (webBrowser1.ReadyState <> WebBrowserReadyState.Complete) 
   Application.DoEvents();
End While
 
webBrowser1.Document.GetElementByTag("textarea")(0).InnerText = "someText"
webBrowser1.Document.GetElementByTag("input")(3).InvokeMember("click")

Open in new window

0
 
LVL 2

Author Comment

by:madivad2
ID: 22640526
Excellent, almost worked straight off the bat, fixed minor coding (you use a C++/C# do you) there was an alien ';' in there. Also GetElementByTag had to be changed to GetElementsVyTagName. changed the array from 3 to 2 and I was off.

The only two parts I don't get is, what is the 'textarea' bit about?

Also, what is happening with the invoke member on the submit? That didn't work for me, (ie, it didn't login), but it did when the InvokeMember was carried out on the 'input'

Actually, running tests, this has given me the best results:
        wb.Navigate("http://someurl.com")
 
        While (wb.ReadyState <> WebBrowserReadyState.Complete)
            Application.DoEvents()
        End While
 
        wb.Document.GetElementById("username").InnerText = "[madivad]"
        wb.Document.GetElementById("password").InnerText = "[password]"
        wb.Document.GetElementsByTagName("input")(2).InvokeMember("click")

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 22641231
A <textarea> element is a multi-line TextBox.

InvokeMember calls the click method on the <input> element, which is the button.
0
 
LVL 2

Author Closing Comment

by:madivad2
ID: 31502847
with minor amendments, this worked as planned (see code below), thanks o' LearnedOne :-)
0
 
LVL 2

Author Comment

by:madivad2
ID: 22641439
so why didn't the previous one work involving the submit button? That appears (to me) to be more accurate stating the name of the input, being the submit button, otherwise, the array index could be skewed all over the place on a form with many fields
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 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