我正在尝试使用VBA打开并登录Internet网站。
我正在为代码的HTML部分苦苦挣扎。HTML代码中没有"名称"属性。这就是让我失望的原因。
检查的参考:
Microsoft Internet控件,
Microsoft脚本控制1.0,
Microsoft HTML对象库
html登录文本框:
<input class="ui-autocomplete-input" id="BIA_Login" autofocus="" type="text" autocomplete="off">
html用于密码文本框:
<input class="ui-autocomplete-input" id="BIA_Pass" type="password" autocomplete="off">
Private Sub CommandButton21_Click()
Const cURL = "xxxxxxxxxxx.com"
Const cUsername = "xxxxxxx"
Const cPassword = "xxxxxxx"
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.busy: DoEvents: Loop
Set doc = IE.document
Set LoginForm = doc.forms(0)
Set UserNameInputBox = LoginForm.elements("BIA_Login")
UserNameInputBox.Value = cUsername
Set PasswordInputBox = LoginForm.elements("BIA_Pass")
PasswordInputBox.Value = cPassword
使用 getElementByID
并直接使用文档元素。
Set UserNameInputBox = doc.getElementById("BIA_Login")
UserNameInputBox.Value = cUsername
Set PasswordInputBox = doc.getElementById("BIA_Pass")
PasswordInputBox.Value = cPassword