Solved

logging into web sites with VB.NET

Posted on 2008-10-03
6
401 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 500 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
send messages to whatsapp programatically 2 67
Close form "before" open 3 49
Crystal reports vb.net 2 54
VB.net SQLCommandBuilder Insert New Records From DataGridView 3 25
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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