2017-07-07 35 views
1

我希望完成2个简单的任务。输入密码,并提交用户名和密码https://ktt.key.com使用VBA登录银行

我目前能够在用户名选项卡中显示我的名字,但在输入密码时遇到问题。请提供方式提交。谢谢你们的帮助。

这是我迄今为止...

Sub login() 
    Dim IE As Object 
    Dim HTMLDoc As Object 
    Dim objCollection As Object 


    Const navOpenInNewTab = &H800 
    Set IE = CreateObject("InternetExplorer.Application") 
    IE.Visible = True 
    IE.Navigate "https://ktt.key.com/ktt/cmd/logon" 

    Do While IE.Busy Or IE.ReadyState <> 4: Loop 

    Set HTMLDoc = IE.document 
    Set htmlColl = HTMLDoc.getElementsByName("moduleTarget") 

    With HTMLDoc 
    HTMLDoc.getElementById("userId").Value = "xxxxx" 
    HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx" 
    End With 




End Sub 

回答

0

我注意到你有objCollection设置为对象,所以我会用一个填充您的密码字段。

变化:

With HTMLDoc 
    HTMLDoc.getElementById("userId").Value = "xxxxx" 
    HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx" 
End With 

要:

With HTMLDoc 
    HTMLDoc.getElementById("userId").Value = "xxxxx" 
End With 

然后在其下方贴:

Set objCollection = HTMLDoc.getelementsbyname("txtPassword") 
objCollection(0).Value = "1234" 'This is your password 

那么这是什么一样,它设置一个新的对象到txtPassword元素集合。然后它需要第一个索引(“txtPassword”下只有一个索引)并指定您选择的值。完整的代码(从With HTMLDoc下)应该是这样的:

With HTMLDoc 
    HTMLDoc.getElementById("userId").Value = "xxxxx" 
End With 

Set objCollection = HTMLDoc.getelementsbyname("txtPassword") 
objCollection(0).Value = "1234" 'This is your password 

让我知道这对你的作品。

+0

我再次尝试,但我完全尝试过之前。这就是为什么我转移到moduleTarget。思考也许实际的输入点被隐藏在可能的moduleTarget由于某种原因。 –

+0

当我尝试这样做时出现的错误是“运行时错误”462:远程服务器机器不存在或不可用“ –

+0

我还注意到一件事,对于”txtPassword“,没有相邻的”value =“像“txtUserID”,我认为试图设置值是错误的地方,那是什么让我觉得moduleTarget –