2017-07-07 118 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 –