Solved

Login to my favorite web site

Posted on 2011-02-22
15
403 Views
Last Modified: 2012-06-27
Looking for code to login to my favorite https:// web site using my userID and PW. I am experienced in vba and VB6, but new to vs2010 and ASP.NET. I've been studying these newer programming techniques, but need help in getting started in ASP.NET. I can find the tags in my web site using IE8 and F12 to search or outline the DOMs and pick out the userID, PW, and submit if button omitted by using innerText. Your help is greatly appreciated.
Note: I've tried other code snippets found on the web but they appear to be for earlier versions of .NET and give me errors when pasted in VS2010.
0
Comment
Question by:investalert
  • 9
  • 6
15 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 34954114
Are you using the WebBrowser component?
0
 

Author Comment

by:investalert
ID: 34954267
I can but,... I have struggled with building a Windows Form Application orASP.NET Web Application in VB 2010. I believe it is in my best interest to build it in ASP.NET using Web Application for future expansion. However, I am open to suggestions.
0
 
LVL 10

Expert Comment

by:cdebel
ID: 34954497
This is how i've done my login in the past, using a WebBrowser.  You probably can do that without putting the object on a form...

 
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If Not bSendPasswordPostBack Then
            Dim sUserNameField As String = "ctl00_ContentPlaceHolder1_UserName"
            Dim sUserPasswordField As String = "ctl00_ContentPlaceHolder1_Password"
            Dim sSubmitButton As String = "ctl00_ContentPlaceHolder1_btnLogin"

            bSendPasswordPostBack = True
            WebBrowser1.Document.GetElementById(sUserNameField).InnerText = "MyUserName"
            WebBrowser1.Document.GetElementById(sUserPasswordField).InnerText = "MyPassword"
            WebBrowser1.Document.GetElementById(sSubmitButton).InvokeMember("click")
        Else
            bSendPasswordPostBack = False
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sMyWebSite As String = "https://yourwebsite.com"

        WebBrowser1.Navigate(sMyWebSite)
    End Sub

Open in new window


What is the web site that you are trying to access?  Because you say that you can't find the tags for the login, but they must be somewhere...
0
 
LVL 10

Expert Comment

by:cdebel
ID: 34954520
Note: bSendPasswordPostBack is a boolean to make sure that you won't fill up the username & password on 2nd DocumentCompleted.   I've not shown the declaration so here it is:

Private bSendPasswordPostBack As Boolean
0
 

Author Comment

by:investalert
ID: 34954726
Thanks of the quick reply. I tried it in VS2010 and get the following:

bSendPasswordPostBack is noted with error message "Expression is a value and therefore cannot be the target of an assignment" in If Statement.

And Yes, I have the tags for the userID and PW. They are XXXXNUM and XXXXPass.  

 The HTML is shown below.
<DIV id="logonBox">
<FORM id="Logon" onsubmit="return handleLogonSubmit()" method="post" name="Logon" action="j_security_check">
<INPUT id="fp_syslang" type="hidden" name="fp_syslang" value="" /> <INPUT id="fp_software" type="hidden" name="fp_software" value="" /> <INPUT id="fp_userlang" type="hidden" name="fp_userlang" value="" /> <INPUT id="fp_display" type="hidden" name="fp_display" value="" /> <INPUT id="fp_lang" type="hidden" name="fp_lang" value="" /> <INPUT id="fp_timezone" type="hidden" name="fp_timezone" value="" /> <INPUT id="fp_browser" type="hidden" name="fp_browser" value="" /> <INPUT type="hidden" name="LogonToken" value="" /> <INPUT type="hidden" name="PageType" value="" /> <LABEL id="XXXXNumLabel" for="XXXXNum">Online ID</LABEL> <INPUT onkeydown="ChangeFocus(event);" id="XXXXNum" class="loginField" onkeypress="removeErrorMessageDiv()" aria-labelledby="messageLoginErrorLabel XXXXNumLabel" aria-required="true" maxLength="20" size="25" name="j_username" value="" /> <LABEL for="XXXXPass">Password</LABEL> <INPUT id="XXXXPass" class="loginField" onkeypress="removeErrorMessageDiv()" aria-required="true" maxLength="12" size="25" type="password" name="j_password" value="" /><BUTTON class="nAction" onclick="false" type="submit">Log On</BUTTON> 
<P class="textSmall">
Forgot Your <A href="https://www.XXXX.com/inet/ent_proof/proofingEvent?action=Init&event=forgotOnlineId">Online ID</A> or <A href="https://www.XXXX.com/inet/ent_proof/proofingEvent?action=Init&event=forgotPassword">Password</A>?
</P>
<P class="textSmall">
<A href="https://www.XXXX.com/inet/ent_proof/proofingEvent?action=Init&event=registration"><STRONG>Register with XXXX.com</STRONG></A>
</P>
</FORM>
</DIV>

Open in new window

0
 

Author Comment

by:investalert
ID: 34954807
By the way, I did add the webBrowser control to my Form, if that makes any difference.
0
 
LVL 10

Expert Comment

by:cdebel
ID: 34954815
Sorry for that, as i said, i forgot to include the declaration for bSendPasswordPostBack.
In this sample, my form name is Form1 as you can see.

 
Public Class Form1
    Private bSendPasswordPostBack As Boolean

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If Not bSendPasswordPostBack Then
            Dim sUserNameField As String = "ctl00_ContentPlaceHolder1_UserName"
            Dim sUserPasswordField As String = "ctl00_ContentPlaceHolder1_Password"
            Dim sSubmitButton As String = "ctl00_ContentPlaceHolder1_btnLogin"

            bSendPasswordPostBack = True
            WebBrowser1.Document.GetElementById(sUserNameField).InnerText = "MyUserName"
            WebBrowser1.Document.GetElementById(sUserPasswordField).InnerText = "MyPassword"
            WebBrowser1.Document.GetElementById(sSubmitButton).InvokeMember("click")
        Else
            bSendPasswordPostBack = False
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sMyWebSite As String = "https://yourwebsite.com"

        bSendPasswordPostBack = False
        WebBrowser1.Navigate(sMyWebSite)
    End Sub
End Class

Open in new window

0
Highfive Gives IT Their Time Back

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!

 

Author Comment

by:investalert
ID: 34955015
Thanks for the reply. Your code goes to the web site and enters the userID and PW. Need to go to meeting and will look at the detail later and respond. Thanks again cedebel!
0
 

Author Comment

by:investalert
ID: 34979185
OK, got my user name and password entered in the boxes as needed. However, the submit button does not have an ID. I entered the code below and it works, but it causes a circular execution meaning that it enters a continous loop and I don't know how to stop it. Also, when I manually click the submit button on the web page, the web page shows it is trying to navigate to the next page but hangs up. What else do I need to do?
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
        For Each webpageelement As HtmlElement In allelements
            If webpageelement.InnerText = "Log On" Then
                webpageelement.InvokeMember("click")
            End If

Open in new window

0
 

Author Comment

by:investalert
ID: 34979208
Here is the next web page I need to go to:

 https://www.XXXX.com/inet/ent_logon/Logon
0
 

Author Comment

by:investalert
ID: 34979378
It appears the "bSendPasswordPostBack = False" is causing a Log Off and then the page reloads and enters the UserID and Password. This is a loop that continues until the close button is clicked or the Stop Debugging is pressed.

The logon page where the UserID and Password are entered is shown below:

https://www.xxxx.com/inet/ent_logon/Logon

The page to navigate to after the logon is complete is:

https://www.XXXX.com/inet/ent_home/CpHome
0
 
LVL 10

Accepted Solution

by:
cdebel earned 250 total points
ID: 34979452
Maybe you got to to take the problem in the other way with the bSendPasswordPostBack.

It's there to know if it's time to fill up the user name & password and submit.   But if you keep loading other pages it won't be useful.

In your Form Load, set it to true.  And in DocumentCompleted, remove the "NOT" in the IF statement.  In the IF statement (at line 11 in my last code), set it to FALSE.  And Remove the ELSE statement.  This way it will really happen only ONCE, on startup of your application.

0
 
LVL 10

Expert Comment

by:cdebel
ID: 34979484
I've a meeting to prepare, so i'll be back in 2h.
0
 

Author Comment

by:investalert
ID: 34980489
OK, got all the bugs worked out and web page logged on and navigate to correct page. Thanks for your help.
0
 

Author Closing Comment

by:investalert
ID: 34980517
Had to feness that coding and sequence to get final results. However, expert's guidance was good based on information I provided, which was somewhat limited due to security of my web site.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

18 Experts available now in Live!

Get 1:1 Help Now