Solved

logging into web sites with VB.NET

Posted on 2008-10-03
6
403 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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