Link to home
Start Free TrialLog in
Avatar of madivad2
madivad2

asked on

logging into web sites with VB.NET

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?
Avatar of madivad2
madivad2

ASKER

I have increased the points to maximum, I didn't think this would be a hard one to answer... anybody?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

A <textarea> element is a multi-line TextBox.

InvokeMember calls the click method on the <input> element, which is the button.
with minor amendments, this worked as planned (see code below), thanks o' LearnedOne :-)
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