Consulting

Results 1 to 3 of 3

Thread: Solved: problem with IE GetElementsByTagName

  1. #1
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location

    Solved: problem with IE GetElementsByTagName

    I'm trying to access a web page with automatic filling of input text controls.

    As you can see I can't find a solution to get the input texts.

    here's my code taken by a kb entry. Thanx (project has reference to Microsoft HTML e Microsoft Internet Controls)

    [VBA]Sub IE_login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim aid As String, cu As String, pw As String

    redo:
    aid = Application.InputBox("Please enter aid", "VBAX username", Default:="3")
    cu = Application.InputBox("Please enter your cu", "VBAX Password", Default:="T")
    pw = Application.InputBox("Please enter your pw", "VBAX Password", Default:="M")

    If aid = "" Or cu = "" Or pw = "" Then GoTo redo

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www.brebanca.it/SIT/public/homebanca.jsp?sez=39"
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    ie.Navigate "https://extensivenew.bancalombarda.i...riaenti/breweb"
    'Loop until ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    'Look for password Form by finding test "Password"
    Dim INP As HTMLInputElement
    For Each INP In ie.Document.getElementsByTagName("INPUT")
    If INP.Name = "txtCENT" Then INP.Value = aid
    If INP.Name = "txtCOPR" Then INP.Value = cu
    If INP.Name = "txtCPSW" Then INP.Value = pw
    Next
    If ULogin = False Then MsgBox "User is aleady logged in"
    Set ie = Nothing
    End Sub[/VBA]
    ALe
    Help indigent families: www.bancomadreteresa.org

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    ALe,

    Not sure if it makes a difference, but when I go to https://extensivenew.bancalombarda.i...riaenti/breweb I get the "this page contains both secure and non-secure items" popup, causing it not to proceed.

    Also, why navigate to the first site if you're just going to navigate again?

    The second/final page being navigated to has 2 frames, "invisible" and "Menu".. "Menu" has 2 frames as well, "Header" and "Main" .. the main/login frame (frame name "Main") has a URL of https://extensivenew.bancalombarda.i.../Fr_SYSLog.asp
    On that page, it appears the form name is SYSLog. Your input names are correct (txtCENT, txtCOPR, txtCPSW) but they're not in anything called INPUT
    However, even changing INPUT to SYSLog won't fix it, the reason you're not getting anything is because SYSLog isn't picked up the the "getelementbytagname".. you can change that using:
    [vba] For Each INP In ie.Document.Forms("SYSLog")[/vba]
    or instead of looping like you are, you could also just use:[vba] With ie.Document.Frames("Main").Document.Forms("SYSLog")
    .Item("txtCENT").Value = aid
    .Item("txtCOPR").Value = cu
    .Item("txtCPSW").Value = pw
    '.Submit
    End With[/vba]

    All in all, here is the whole sub, you can choose which of the navigate blocks you want to use (which page you want to use):[vba]Sub IE_login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim aid As String, cu As String, pw As String

    redo:
    aid = Application.InputBox("Please enter aid", "enter aid", Default:="3")
    cu = Application.InputBox("Please enter your cu", "enter cu", Default:="T")
    pw = Application.InputBox("Please enter your pw", "enter pw", Default:="M")

    If aid = "" Or cu = "" Or pw = "" Then GoTo redo

    Set ie = New InternetExplorer
    ie.Visible = True

    'using main page:
    ie.Navigate2 "https://extensivenew.bancalombarda.i...riaenti/breweb"
    'Loop until ie page is fully loaded
    Do Until ie.readyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    With ie.Document.Frames("Main").Document.Forms("SYSLog")
    .Item("txtCENT").Value = aid
    .Item("txtCOPR").Value = cu
    .Item("txtCPSW").Value = pw
    '.Submit
    End With

    'using SYSLog.asp page:
    ie.Navigate2 "https://extensivenew.bancalombarda.i.../Fr_SYSLog.asp"
    'Loop until ie page is fully loaded
    Do Until ie.readyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    With ie.Document.Forms("SYSLog")
    .Item("txtCENT").Value = aid
    .Item("txtCOPR").Value = cu
    .Item("txtCPSW").Value = pw
    '.Submit
    End With

    If ULogin = False Then MsgBox "User is aleady logged in"
    Set ie = Nothing
    End Sub[/vba]
    Matt

  3. #3
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    great mvidas. I'll test your code as soon as possible.

    Regarding your first point, I get the same message about protection. It can be avoided (and I did) using the advanced options of internet.
    internet->properties->protection->custom->mixed content->active (not sure about menus because I haven't the english version)

    2nd point: without going to first page sometimes I had a different HTML code for the second page (I don't know why) so it was a rude trick to avoid this problem.

    I'll test the code the soonest. Thank you very much!
    ALe
    Help indigent families: www.bancomadreteresa.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •