0

I am currently using this Fill user name and password in a webpage using VBA code to log in to a website but I am running into an issue. Since the username and password is already saved on the browser it is adding the uid/pass again and creating an error in the login process. Is there a way I can add some code to clear any previously input uid/pass?

Sub test()
 ' open IE, navigate to the desired page and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://hb2.bankleumi.co.il/e/Login.html"

With ie
    .Visible = True
    .Navigate my_url
    .Top = 50
    .Left = 530
    .Height = 400
    .Width = 400

Do Until Not ie.Busy And ie.readyState = 4
    DoEvents
Loop

End With

' Input the userid and password
ie.Document.getElementById("uid").Value = "testID"
ie.Document.getElementById("password").Value = "testPW"

' Click the "Search" button
ie.Document.getElementById("enter").Click

Do Until Not ie.Busy And ie.readyState = 4
    DoEvents
Loop
 End Sub
Community
  • 1
  • 1
TonyP
  • 333
  • 2
  • 4
  • 19
  • 1
    first check if the value already is the current username, in which case, just move on and click; otherwise try to clear it out with a `.Value = ""` line? – Scott Holtzman Jul 12 '16 at 16:12
  • @ScottHoltzman Brilliant. Clearing it using .value= "" worked perfectly. Thank you very much! If you post it as an answer I would be more than happy to accept it so the thread can close. – TonyP Jul 12 '16 at 16:19

1 Answers1

2

You can test if the currently loaded username is the same, and if so, just click, otherwise, clear out the existing username with a .Value = ""

If ie.Document.getElementById("uid").Value = "testID" Then
Else
  ie.Document.getElementById("uid").Value = ""
  ie.Document.getElementById("password").Value = ""
  ie.Document.getElementById("uid").Value = "testID"
  ie.Document.getElementById("password").Value = "testPW"
End If
Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72