Solved

logging into web sites with VB.NET

Posted on 2008-10-03
6
392 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
Comment Utility
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 500 total points
Comment Utility
>>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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
Comment Utility
with minor amendments, this worked as planned (see code below), thanks o' LearnedOne :-)
0
 
LVL 2

Author Comment

by:madivad2
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now