I have been attempting to input a username and password into a GUI that I am accessing remotely.
Here is my Code:
Dim UNBox As IHTMLInputElement
Dim PWBox As HTMLInputElement
Dim Login As HTMLInputElement
Dim doc As HTMLDocument
Dim LoginInfo As String
Dim UN As String
Dim PSW As String
Dim Webdoc As MSHTML.IHTMLElementCollection
Dim Element As MSHTML.IHTMLInputElement
Dim IE As Object
LoginInfo = CmbNetwork.Value
'launches IE and inputs IP address into the address bar then navigates to the GUI
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.navigate ThisWorkbook.Worksheets("Networks Info").Cells.Find(LoginInfo).Offset(rowoffset:=0, columnoffset:=8).Value
IE.Top = 0
IE.Left = 150
IE.Height = 700
IE.Width = 1000
'Pauses browser window while the GUI loads
Do While IE.readyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("00:00:05"))
Loop
UN = ThisWorkbook.Worksheets("Networks Info").Cells.Find(LoginInfo).Offset(rowoffset:=0, columnoffset:=13)
PSW = ThisWorkbook.Worksheets("Networks Info").Cells.Find(LoginInfo).Offset(rowoffset:=0, columnoffset:=14)
If ThisWorkbook.Worksheets("Networks Info").Cells.Find(LoginInfo).Offset(rowoffset:=0, columnoffset:=12) = "ION-M" Then
Set Webdoc = IE.Document.getElementsByTagName("input")
'Loops through all elements in GUI
For Each Element In Webdoc 'READS THIS LINE
'Finds username text box element and inputs username
If Element.Name = "loginname" Then
Element.innerText = UN
'Finds password text box element and inputs password
ElseIf Element.Name = "loginpwrd" Then
Element.innerText = PSW
End If
Next Element
Set Element = Nothing 'SKIPS TO THIS LINE
The issue that I am having is that when I step through the code(F8) to watch each line execute I have noticed that when it hits the For Each Next loop it skips the loop all together. I know that the username and password text boxes are embedded in a table in the html code.
The input elements are toward the bottom of the html code block GUI HTML code...
<form name="myLogin" onsubmit="return setTimeDiff();" action="index.jsp" method="post">
<input name="loginTimeDiff" type="hidden" value="0"><table border="0">
<tbody>
<tr>
<td align="right">User Name:</td>
<td>
<input name="login" type="hidden" value="login">
<input name="loginname" id="login_name" type="text" size="20" maxlength="20">
</td>
</tr><tr>
<td align="right">Password:</td>
<td>
<input name="loginpwrd" onkeyup="zaehlen(this.value)" type="password" size="20" maxlength="8">
</td>
</tr>
<tr height="25"></tr><tr><td align="center" colspan="2">
<input type="submit" value=" Login "><input type="reset" value=" Reset ">
</td>
It seems that on the line Set Webdoc = IE.Document.getElementsByTagName("input")
that the code does not "see" the input tags in the table. If I back out and try to call anything outside of the tables the code works perfect.
Can anyone please help me to discover what is causing this. I am willing to answer any additional questions. Thank you in advance for any help you can provide!