PDA

View Full Version : Solved: problem with IE GetElementsByTagName



ALe
09-13-2006, 04:23 AM
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.:dunno

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

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.it/tesoreriaenti/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

mvidas
09-13-2006, 06:03 AM
ALe,

Not sure if it makes a difference, but when I go to https://extensivenew.bancalombarda.it/tesoreriaenti/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.it/tesoreriaenti/breweb/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:
For Each INP In ie.Document.Forms("SYSLog")
or instead of looping like you are, you could also just use: With ie.Document.Frames("Main").Document.Forms("SYSLog")
.Item("txtCENT").Value = aid
.Item("txtCOPR").Value = cu
.Item("txtCPSW").Value = pw
'.Submit
End With

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):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.it/tesoreriaenti/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.it/tesoreriaenti/breweb/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
Matt

ALe
09-13-2006, 08:52 AM
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!