PDA

View Full Version : [SOLVED] Automated Login Results in URL Change After More Than One Use



Jim Clayton
07-11-2019, 01:45 PM
Code posted below. After alot of trying I managed to scrape together a macro that it willauto-log me into my bank account. If I try to run it a second time, the URLchanges on me and I get an error message. If I clear my browsing history andclose/re-open the file, it works again. I've tried setting my Internet Options to "Delete Browsing Historyon Exit". I also tried changing "Dim IE As InternetExplorer" to"Dim IE As InternetExplorerMedium" because I read somewhere that thatmight help. Something having to do with this being a secure site and it wasredirecting me to a parent URL. I've been looking like crazy for a solution butit's hard to even figure out the correct way to phrase the question to searchfor one. Would greatly appreciate anyother possible solutions. Tks.
***Also posted on Excel Help Forum here:https://www.excelforum.com/excel-programming-vba-macros/1282204-web-history-prevents-macro-from-running-more-than-one-time.html***


Sub Chase()

Const cURL = "https://chaseonline.chase.com/"
Const cUserID = "XXXXX"
Const cPassword = "XXXXX"

Dim IE As InternetExplorerMedium
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UsernameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim LogOnButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Dim qt As QueryTable

Set IE = New InternetExplorerMedium

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 Username textbox and populate it
'input name="UserID" id="UserID" size="18" value="" class="user-name" type="text"

Set UsernameInputBox = doc.getElementById("UserID")
UsernameInputBox.Value = cUserID

'Get the Password textbox and populate it
'input name="Password" id="Password" size="18" class="user-password" type="password"

Set PasswordInputBox = doc.getElementById("Password")
PasswordInputBox.Value = cPassword

'Get the form input button and click it

Set LogOnButton = doc.getElementById("logon")
LogOnButton.Click

'Wait for the new page to load

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

End Sub