我希望完成2个简单的任务。输入密码,并将用户名和密码提交至https://ktt.key.com
我目前能够在用户名标签中显示我的名字,但输入密码时遇到问题。请提供提交方式。谢谢你的帮助。
这就是我到目前为止......
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 :(得分:0)
我注意到你将objCollection设置为Object,所以我将使用那个填充你的密码字段。
变化:
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
请告诉我这是否适合您。