joshuaatwork
New Member
- Joined
- Feb 28, 2013
- Messages
- 13
I put together about 10 separate macros that will log you into a site using the values in a given cell. I was having trouble with the last one because of AutoComplete remembering the username. So I put in an IF statement, and when I used F8 to go line for line, it works perfectly. However, when I click F5 and just let it play through, it doesn't log in. I tried adding a 5 second delay, but that didn't seem to work. I still get a run-time error when I hit play.
It get hung on this line:
But the complete code is this:
It get hung on this line:
Code:
If doc.getElementById("user_name").Value = cUsername Then
But the complete code is this:
Code:
Sub StreetLinks_Login()
'On Error Resume Next
Dim cURL As String
cURL = Worksheets("Sheet1").Range("B9").Value
Dim cUsername As String
cUsername = Worksheets("Sheet1").Range("D9").Value
Dim cPassword As String
cPassword = Worksheets("Sheet1").Range("E9").Value
Dim ie As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Dim qt As QueryTable
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate cURL
'Wait for initial page to load
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy: DoEvents: Loop
Set doc = ie.document
'Get the only form on the page
Set LoginForm = doc.forms(0)
'Get the User Name textbox and populate it
'input name="Email" id="Email" size="18" value="" class="gaia le val" type="text"
Set UserNameInputBox = doc.getElementById("user_name")
If doc.getElementById("user_name").Value = cUsername Then
Else
UserNameInputBox.Value = cUsername
End If
'Get the password textbox and populate it
'input name="Passwd" id="Passwd" size="18" class="gaia le val" type="password"
Set PasswordInputBox = doc.getElementById("password")
PasswordInputBox.Value = cPassword
'get the form input button and click it
'input class="gaia le button" name="signIn" id="signIn" value="Sign in" type="submit"
doc.getElementById("btnLogin").Click
'Wait for the new page to load
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy: DoEvents: Loop
'On Error GoTo 0
End Sub