I'm trying to run a vb command that will fill in the user ID & password then click on the sign on button. I can get the user id field and password to fill but having a problem with the click on button. Anyone have any suggestions?
Here is my script:
Sub Project()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://website.com"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.User.Value = "MyUserID"
HTMLDoc.all.Password.Value = "PASS123"
For Each Html_Element In HTMLDoc.getElementsByTagName("signOnButton")
If element.getAttribute("class") = "signOnButton" Then
element.InvokeMember ("onclick")
End If
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
Here is the html source for the button from the website I'm trying to log into
<div class="SignOnButton">
<div id="signButton" class="floatLeft" ></div>
<div class="floatRight padding-left-1"><a class="bold" href="/pass/one.fps" >Forgot Password?</a></div>
Here is my script:
Sub Project()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://website.com"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.User.Value = "MyUserID"
HTMLDoc.all.Password.Value = "PASS123"
For Each Html_Element In HTMLDoc.getElementsByTagName("signOnButton")
If element.getAttribute("class") = "signOnButton" Then
element.InvokeMember ("onclick")
End If
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
Here is the html source for the button from the website I'm trying to log into
<div class="SignOnButton">
<div id="signButton" class="floatLeft" ></div>
<div class="floatRight padding-left-1"><a class="bold" href="/pass/one.fps" >Forgot Password?</a></div>